﻿/*
    Copyright (C) 2008, wj2929, wj2929@gmail.com

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    *KEEP THIS HEADER INFORMATION*
*/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.IO;
using System.Threading;

using System.Xml.Linq;
using System.Xml;
using mjRegister.BAL;
using mjRegister.Entity;

using System.Collections;
using System.Diagnostics;
using Microsoft.VisualBasic;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;
using System.Globalization;
using System.Net;
using System.Collections.Specialized;

namespace mjRegister
{
    public partial class Form2 : Form
    {
        public int delayConnect = 3;//延迟间隔默认3秒
        IList<Thread> lstThread = new List<Thread>();

        string configPath = Common.GetConfigPath();

        string accountconfigxmlfile = string.Empty;

        public Hashtable htAccountInfo = new Hashtable();

        public Hashtable htAccountInfoByUid = new Hashtable();

        IList<AccountGroupInfo> accountGroupInfos = new List<AccountGroupInfo>();

        Hashtable htAccountGroupInfo = new Hashtable();

        private ListViewColumnSorter lvwColumnSorter;

        public IList<AppInfo> addAppInfos = new List<AppInfo>();

        [DllImport("wininet.dll", SetLastError = true)]
        public static extern bool InternetGetCookie(string url, string cookieName, StringBuilder cookieData, ref int size);

        [DllImport("wininet.dll", SetLastError = true)]
        public static extern bool InternetSetCookie(string url, string cookieName, string cookieData);

        public Form2()
        {
            InitializeComponent();

            lvwColumnSorter = new ListViewColumnSorter(0,3);
            this.listView1.ListViewItemSorter = lvwColumnSorter;
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            SetControlDisabled();

            Thread t = new Thread(new ThreadStart(Init));
            t.Start();
            lstThread.Add(t);

            this.ddlIniTactic.SelectedIndex = 0;
        }

        //系统初始化
        void Init()
        {
            try
            {
                this.Invoke(new DAppendText(AppendText),
                    string.Format("[{0}]：正在初始化分组及账户，请稍候……\n",
                        DateTime.Now.ToString("HH:mm:ss")));

                if (!Directory.Exists(configPath))
                    Directory.CreateDirectory(configPath);

                accountconfigxmlfile = Path.Combine(configPath, "accounts.xml");

                if (AccountGroup.CheckAccountGroupXmlFileExist())
                {
                    accountGroupInfos = AccountGroup.GetAccountGroupInfos();
                }
                else
                    AccountGroup.CreateAccountGroupXmlFile();

                this.Invoke(new DInitddlGroup(InitddlGroup), accountGroupInfos);
                this.Invoke(new DInitddlMoveGroup(InitddlMoveGroup), accountGroupInfos);

                IList<AccountInfo> accountInfos = new List<AccountInfo>();
                if (Account.CheckAccountXmlFileExist())
                {
                    accountInfos = Account.GetAccountInfos();
                }
                else
                    Account.CreateAccountXmlFile();

                for (int i = 0; i < accountInfos.Count; i++)
                {
                    AccountInfo accountInfo = accountInfos[i];
                    htAccountInfo[accountInfo.Email] = accountInfo;

                    if (accountInfo.UserInfo != null)
                        htAccountInfoByUid[accountInfo.UserInfo.uid] = accountInfo;

                    string groupName;

                    if (accountInfo.ActiveStatus == ActiveStatus.AlreadyActive || accountInfo.ActiveStatus == ActiveStatus.AppForbided)
                        groupName = SystemGroup.已验证组.ToString();
                    else if (accountInfo.ActiveStatus == ActiveStatus.NoVerifyActive)
                        groupName = SystemGroup.未验证组.ToString();
                    else
                        groupName = SystemGroup.未激活或账户错误组.ToString();

                    AddAccountToAccountGroup(groupName, accountInfo, false);

                    AddAccountToAccountGroup(SystemGroup.全部.ToString(), accountInfo, false);

                    if (accountInfo.ActiveStatus == ActiveStatus.AppForbided)
                        AddAccountToAccountGroup(SystemGroup.组件被封组.ToString(), accountInfo, false);

                    if (accountInfo.IsMaster)
                        AddAccountToAccountGroup(SystemGroup.主号组.ToString(), accountInfo, false);

                    if (accountInfo.AccountGroupInfo != null)
                        AddAccountToAccountGroup(accountInfo.AccountGroupInfo.Name, accountInfo, false);
                    else
                        AddAccountToAccountGroup(SystemGroup.未分组.ToString(), accountInfo, false);
                }
                this.Invoke(new DInitListView(InitListView), accountInfos);

                this.Invoke(new DRestoreControlEnabled(RestoreControlEnabled));

                this.Invoke(new DAppendText(AppendText),
                    string.Format("[{0}]：初始化完成！\n",
                        DateTime.Now.ToString("HH:mm:ss")));
            }
            catch (Exception ex)
            {
                using (StreamWriter sw = new StreamWriter(Path.Combine(Application.StartupPath, "error.txt"), false, Encoding.Default))
                {
                    sw.WriteLine(ex);
                    this.Invoke(new DAppendText(AppendText), string.Format("[{0}]：出现错误：{1}",
                            DateTime.Now.ToString("HH:mm:ss"),
                            ex.Message));
                }
            }
        }

        //加载/刷新ListView列表
        delegate void DInitListView(IList<AccountInfo> accountInfos);
        void InitListView(IList<AccountInfo> accountInfos)
        {
            for (int i = 0; i < accountInfos.Count; i++)
            {
                AccountInfo accountInfo = accountInfos[i];
                ListViewItem item = new ListViewItem(
                    new string[] { 
                            (i+1).ToString(),//.PadLeft(accountInfos.Count.ToString().Length,'0'),
                            accountInfo.Email, 
                            accountInfo.Password, 
                            accountInfo.UserInfo == null ? string.Empty : accountInfo.UserInfo.uid, 
                            accountInfo.UserInfo == null ? string.Empty : accountInfo.UserInfo.real_name, 
                            Account.GetAccountActiveStatusDesctiption(accountInfo.ActiveStatus),
                            accountInfo.AccountGroupInfo == null ? string.Empty : accountInfo.AccountGroupInfo.Name,
                            accountInfo.IsMaster ? "是" : "否"
                        }
                );
                item.Tag = accountInfo;
                accountInfo.Tag = item;
                htAccountInfo[accountInfo.Email] = accountInfo;

                if (accountInfo.UserInfo != null)
                    htAccountInfoByUid[accountInfo.UserInfo.uid] = accountInfo;

                this.listView1.Items.Add(item);
            }
        }

        //初始化本地群组列表
        delegate void DInitddlGroup(IList<AccountGroupInfo> accountGroupInfos);
        void InitddlGroup(IList<AccountGroupInfo> accountGroupInfos)
        {
            this.ddlGroup.Items.Clear();
            this.ddlGroup.Items.Add(SystemGroup.全部.ToString());
            this.ddlGroup.Items.Add(SystemGroup.未分组.ToString());
            this.ddlGroup.Items.Add(SystemGroup.未验证组.ToString());
            this.ddlGroup.Items.Add(SystemGroup.未激活或账户错误组.ToString());
            this.ddlGroup.Items.Add(SystemGroup.已验证组.ToString());
            this.ddlGroup.Items.Add(SystemGroup.主号组.ToString());
            this.ddlGroup.Items.Add(SystemGroup.组件被封组.ToString());
            this.ddlGroup.SelectedIndex = 0;
            for (int i = 0; i < accountGroupInfos.Count; i++)
            {
                AccountGroupInfo accountGroupInfo = accountGroupInfos[i];
                htAccountGroupInfo[accountGroupInfo.Name] = accountGroupInfo;
                this.ddlGroup.Items.Add(accountGroupInfo.Name);
            }
        }

        //初始化本地群组列表
        delegate void DInitddlMoveGroup(IList<AccountGroupInfo> accountGroupInfos);
        void InitddlMoveGroup(IList<AccountGroupInfo> accountGroupInfos)
        {
            this.ddlMoveGroup.Items.Clear();
            this.ddlMoveGroup.Items.Add("移动到分组……");
            this.ddlMoveGroup.SelectedIndex = 0;
            for (int i = 0; i < accountGroupInfos.Count; i++)
            {
                AccountGroupInfo accountGroupInfo = accountGroupInfos[i];
                htAccountGroupInfo[accountGroupInfo.Name] = accountGroupInfo;
                this.ddlMoveGroup.Items.Add(accountGroupInfo.Name);
            }
        }

        //账户导入
        //文件格式：
        //password email
        //............(换行)
        //password email
        void ImportAccountFile(string accountfile)
        {
            if (!string.IsNullOrEmpty(accountfile))
            {
                try
                {
                    if (File.Exists(accountfile))
                    {
                        string re = "^(?<email>(?<username>[^@\\s!#\\$%\\^&\\(\\)]+)@(?<domain>(?:[-a-z0-9A-Z]+\\.)+[a-zA-Z]{2,}))\\s+(?<password>.*?)$";
                        string[] accounts = File.ReadAllLines(accountfile);
                        for (int i = 0; i < accounts.Length; i++)
                        {
                            string account = accounts[i];
                            if (account != string.Empty && Regex.IsMatch(account,re))
                            {
                                Match match = Regex.Match(account,re);
                                AccountInfo accountInfo = new AccountInfo
                                {
                                    Email = match.Result("${email}"),
                                    Password = match.Result("${password}"),
                                    ActiveStatus = ActiveStatus.NoVerifyActive
                                };
                                if (htAccountInfo[accountInfo.Email] == null)
                                {
                                    Account.Add(accountInfo);
                                    htAccountInfo[accountInfo.Email] = accountInfo;
                                    ListViewItem item = new ListViewItem(
                                        new string[] { 
                                        htAccountInfo.Count.ToString().PadLeft(htAccountInfo.Count.ToString().Length,'0'),
                                        accountInfo.Email, 
                                        accountInfo.Password, 
                                        accountInfo.UserInfo == null ? string.Empty : accountInfo.UserInfo.uid, 
                                        accountInfo.UserInfo == null ? string.Empty : accountInfo.UserInfo.real_name, 
                                        Account.GetAccountActiveStatusDesctiption(accountInfo.ActiveStatus)
                                    }
                                    );
                                    item.Tag = accountInfo;
                                    accountInfo.Tag = item;

                                    this.listView1.Items.Add(item);

                                    AddAccountToAccountGroup(SystemGroup.全部.ToString(), accountInfo, false);
                                    AddAccountToAccountGroup(SystemGroup.未分组.ToString(), accountInfo, false);
                                    AddAccountToAccountGroup(SystemGroup.未验证组.ToString(), accountInfo, false);
                                }
                            }
                        }
                        MessageBox.Show("导入完成！");
                    }
                    else
                        MessageBox.Show("账户文件不存在！");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("account.txt内容格式错误！");
                }
            }
            else
                MessageBox.Show("请填写帐号文件路径");

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string accountfile = this.textBox1.Text.Trim();
            ImportAccountFile(accountfile);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            IList<AccountInfo> accounts = new List<AccountInfo>();

            for (int i = 0; i < this.listView1.Items.Count; i++)
            {
                if (this.listView1.Items[i].Checked)
                {
                    ListViewItem listViewItem = this.listView1.Items[i];
                    listViewItem.SubItems[4].Text = "等待验证中……";
                    AccountInfo account = (AccountInfo)listViewItem.Tag;
                    accounts.Add(account);
                }
            }
            if (accounts.Count == 0)
            {
                MessageBox.Show("尚未选择项！");
                return;
            }

            this.SetControlDisabled();

            Thread t = new Thread(new ParameterizedThreadStart(VerifyAccount));
            t.Start(accounts);
            lstThread.Add(t);
        }

        //批量验证账户激活状态并对之初始化
        void VerifyAccount(object obj)
        {
            this.Invoke(new DAppendText(AppendText),
                string.Format("[{0}]：开始验证账户……\n",
                    DateTime.Now.ToString("HH:mm:ss")));

            IList<AccountInfo> accounts = (List<AccountInfo>)obj;
            for (int i = 0; i < accounts.Count; i++)
            {
                AccountInfo accountInfo = (AccountInfo)accounts[i];

                ListViewItem listViewItem = (ListViewItem)accountInfo.Tag;

                this.Invoke(new DSetListViewSubItemUidAndActiveStatusText(SetListViewSubItemUidAndActiveStatusText),
                    listViewItem,
                    accountInfo.UserInfo == null ? string.Empty : accountInfo.UserInfo.uid,
                    accountInfo.UserInfo == null ? string.Empty : accountInfo.UserInfo.real_name,
                    "正在验证中……");

                User user = new User();

                user.UserInfo = accountInfo.UserInfo;

                this.Invoke(new DAppendText(AppendText),
                    string.Format("[{0}]：[{1}]开始登录系统……",
                        DateTime.Now.ToString("HH:mm:ss"),
                        string.Format("{0}", accountInfo.Email)));

                if (!user.Login(accountInfo))
                {
                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：[{1}]验证错误：帐号或密码不太对吧！ 进度：{2}",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", accountInfo.Email, accountInfo.UserInfo == null ? string.Empty : accountInfo.UserInfo.real_name),
                            string.Format("{0}/{1}", (i + 1).ToString(), accounts.Count.ToString())));

                    if (accountInfo.UserInfo != null)
                        htAccountInfoByUid.Remove(accountInfo.UserInfo.uid);

                    AddAccountToAccountGroup(SystemGroup.未激活或账户错误组.ToString(), accountInfo, false);
                    DeleteAccountFromAccountGroup(SystemGroup.未验证组.ToString(), accountInfo);
                    DeleteAccountFromAccountGroup(SystemGroup.已验证组.ToString(), accountInfo);
                    this.Invoke(new DSetListViewSubItemUidAndActiveStatusText(SetListViewSubItemUidAndActiveStatusText), listViewItem, "", "","验证错误：帐号或密码不太对吧");
                }
                else
                {
                    accountInfo.ActiveStatus = ActiveStatus.AlreadyActive;
                    accountInfo.UserInfo = user.UserInfo;

                    htAccountInfoByUid[accountInfo.UserInfo.uid] = accountInfo;

                    Account.EditAccountInfo(accountInfo);
                    accountInfo.FriendInfos = user.GetAllUserInfos();
                    Account.StaticFriends(accountInfo);
                    AddAccountToAccountGroup(SystemGroup.已验证组.ToString(), accountInfo, false);
                    DeleteAccountFromAccountGroup(SystemGroup.未验证组.ToString(), accountInfo);
                    DeleteAccountFromAccountGroup(SystemGroup.未激活或账户错误组.ToString(), accountInfo);
                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：[{1}]成功登录系统，并获取好友列表，缓存到本地！ 进度：{2}",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name),
                            string.Format("{0}/{1}", (i + 1).ToString(), accounts.Count.ToString())));
                    this.Invoke(new DSetListViewSubItemUidAndActiveStatusText(SetListViewSubItemUidAndActiveStatusText), 
                        listViewItem,
                        accountInfo.UserInfo == null ? string.Empty : accountInfo.UserInfo.uid,
                        accountInfo.UserInfo == null ? string.Empty : accountInfo.UserInfo.real_name,
                        "验证通过");
                    user.Logout();
                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：[{1}]退出系统！\n",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name)));

                }
                //if (i + 1 < accounts.Count)
                //    Thread.Sleep(delayConnect * 1000);

            }
            this.Invoke(new DAppendText(AppendText),
                string.Format("[{0}]：验证账户完成！",
                    DateTime.Now.ToString("HH:mm:ss")));
            this.Invoke(new DRestoreControlEnabled(RestoreControlEnabled));
        }

        //批量验证账户组件被封状态
        void VerifyAccountAppForbidedStatus(object obj)
        {
            this.Invoke(new DAppendText(AppendText),
                string.Format("[{0}]：开始验证账户组件被封状态……\n",
                    DateTime.Now.ToString("HH:mm:ss")));

            IList<AccountInfo> accounts = (List<AccountInfo>)obj;
            for (int i = 0; i < accounts.Count; i++)
            {
                AccountInfo accountInfo = (AccountInfo)accounts[i];

                ListViewItem listViewItem = (ListViewItem)accountInfo.Tag;

                this.Invoke(new DSetListViewSubItemUidAndActiveStatusText(SetListViewSubItemUidAndActiveStatusText),
                    listViewItem,
                    accountInfo.UserInfo == null ? string.Empty : accountInfo.UserInfo.uid,
                    accountInfo.UserInfo == null ? string.Empty : accountInfo.UserInfo.real_name,
                    "正在验证中……");

                User user = new User();

                user.UserInfo = accountInfo.UserInfo;

                this.Invoke(new DAppendText(AppendText),
                    string.Format("[{0}]：[{1}]开始登录系统……",
                        DateTime.Now.ToString("HH:mm:ss"),
                        string.Format("{0}", accountInfo.Email)));

                if (!user.Login(accountInfo))
                {
                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：[{1}]验证错误：帐号或密码不太对吧！ 进度：{2}",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", accountInfo.Email, accountInfo.UserInfo == null ? string.Empty : accountInfo.UserInfo.real_name),
                            string.Format("{0}/{1}", (i + 1).ToString(), accounts.Count.ToString())));

                    if (accountInfo.UserInfo != null)
                        htAccountInfoByUid.Remove(accountInfo.UserInfo.uid);

                    AddAccountToAccountGroup(SystemGroup.未激活或账户错误组.ToString(), accountInfo, true);
                    DeleteAccountFromAccountGroup(SystemGroup.未验证组.ToString(), accountInfo);
                    DeleteAccountFromAccountGroup(SystemGroup.已验证组.ToString(), accountInfo);
                    this.Invoke(new DSetListViewSubItemUidAndActiveStatusText(SetListViewSubItemUidAndActiveStatusText), listViewItem, "", "", "验证错误：帐号或密码不太对吧");
                }
                else
                {
                    if (user.CheckAppForbided())
                    {
                        accountInfo.ActiveStatus = ActiveStatus.AppForbided;
                        AddAccountToAccountGroup(SystemGroup.组件被封组.ToString(), accountInfo, true);
                    }
                    else
                    {
                        accountInfo.ActiveStatus = ActiveStatus.AlreadyActive;
                        AddAccountToAccountGroup(SystemGroup.已验证组.ToString(), accountInfo, true);
                    }
                    accountInfo.UserInfo = user.UserInfo;

                    htAccountInfoByUid[accountInfo.UserInfo.uid] = accountInfo;

                    Account.EditAccountInfo(accountInfo);
                    DeleteAccountFromAccountGroup(SystemGroup.未验证组.ToString(), accountInfo);
                    DeleteAccountFromAccountGroup(SystemGroup.未激活或账户错误组.ToString(), accountInfo);
                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：[{1}]成功登录系统，组件{3}被封！ 进度：{2}",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name),
                            string.Format("{0}/{1}", (i + 1).ToString(), accounts.Count.ToString()),
                            accountInfo.ActiveStatus == ActiveStatus.AppForbided ? string.Empty : "未"));

                    this.Invoke(new DSetListViewSubItemUidAndActiveStatusText(SetListViewSubItemUidAndActiveStatusText),
                        listViewItem,
                        accountInfo.UserInfo == null ? string.Empty : accountInfo.UserInfo.uid,
                        accountInfo.UserInfo == null ? string.Empty : accountInfo.UserInfo.real_name,
                        Account.GetAccountActiveStatusDesctiption(accountInfo.ActiveStatus));
                    user.Logout();
                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：[{1}]退出系统！\n",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name)));

                }
                //if (i + 1 < accounts.Count)
                //    Thread.Sleep(delayConnect * 1000);

            }
            this.Invoke(new DAppendText(AppendText),
                string.Format("[{0}]：验证账户组件被封状态完成！",
                    DateTime.Now.ToString("HH:mm:ss")));
            this.Invoke(new DRestoreControlEnabled(RestoreControlEnabled));
        }

        //设置控件不可操作
        delegate void DSetControlDisabled();
        void SetControlDisabled()
        {
            this.ddlGroup.Enabled = false;
            this.ddlMoveGroup.Enabled = false;
            this.button11.Enabled = false;
            this.button2.Enabled = false;
            this.button1.Enabled = false;
            this.button9.Enabled = false;
            this.button12.Enabled = false;
            this.button4.Enabled = false;
            this.button16.Enabled = false;
            this.button17.Enabled = false;
            this.button18.Enabled = false;
            this.button19.Enabled = false;
            this.button6.Enabled = false;
            this.listView1.Enabled = false;
            this.checkBox1.Enabled = false;
            this.button20.Enabled = false;
            this.button22.Enabled = false;
            this.button23.Enabled = false;
            this.button24.Enabled = false;
            this.button25.Enabled = false;
            this.button26.Enabled = false;
            this.button27.Enabled = false;
            this.button28.Enabled = false;
            this.button30.Enabled = false;
            this.button31.Enabled = false;
            this.button32.Enabled = false;
            this.button33.Enabled = false;

        }

        //恢复控件可操作状态
        delegate void DRestoreControlEnabled();
        void RestoreControlEnabled()
        {
            this.ddlGroup.Enabled = true;
            this.ddlMoveGroup.Enabled = true;
            this.button11.Enabled = true;
            this.button2.Enabled = true;
            this.button1.Enabled = true;
            this.button17.Enabled = true;
            this.button18.Enabled = true;
            this.button16.Enabled = true;
            this.button4.Enabled = true;
            this.button6.Enabled = true;
            this.listView1.Enabled = true;
            this.checkBox1.Enabled = true;
            this.button20.Enabled = true;
            this.button21.Enabled = true;
            this.button22.Enabled = true;
            this.button23.Enabled = true;
            this.button24.Enabled = true;
            this.button25.Enabled = true;
            this.button26.Enabled = true;
            this.button27.Enabled = true;
            this.button28.Enabled = true;
            this.button30.Enabled = true;
            this.button31.Enabled = true;
            this.button32.Enabled = true;
            this.button33.Enabled = true;
            if (this.ddlGroup.SelectedIndex > 6)
            {
                this.button9.Enabled = true;
                this.button12.Enabled = true;
                this.button19.Enabled = true;
                this.button8.Enabled = true;
                this.button10.Enabled = true;
            }
            else
            {
                this.button9.Enabled = false;
                this.button12.Enabled = false;
                this.button19.Enabled = false;
                this.button8.Enabled = false;
                this.button10.Enabled = false;
            }
        }

        delegate void DSetListViewSubItemUidAndActiveStatusText(ListViewItem listViewItem, string uid, string real_name, string statusText);
        void SetListViewSubItemUidAndActiveStatusText(ListViewItem listViewItem, string uid,string real_name,string statusText)
        {
            listViewItem.SubItems[3].Text = uid;
            listViewItem.SubItems[4].Text = real_name;
            listViewItem.SubItems[5].Text = statusText;
        }

        private void button7_Click(object sender, EventArgs e)
        {
            try
            {
                delayConnect = int.Parse(this.textBox2.Text.Trim());
            }
            catch (Exception ex)
            {
                MessageBox.Show("【执行间隔】应填写整型数字！");
                return;
            }
            if (delayConnect <= 0)
            {
                MessageBox.Show("【执行间隔】应大于0，将恢复默认值：3！");
                delayConnect = 3;
                this.textBox2.Text = delayConnect.ToString();
                return;
            }
            MessageBox.Show(string.Format("设置成功，当前执行间隔修改为{0}秒", delayConnect.ToString()));
        }

        //判断是否本地系统群组名称
        bool IsSystemGroupName(string groupName)
        {
            try
            {
                Enum.Parse(typeof(SystemGroup), groupName, true);
                return true;
            }
            catch 
            {
                return false;
            }
        }

        //移动账户到本地分组
        private void ddlMoveGroup_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.ddlMoveGroup.SelectedIndex != 0)
            {
                IList<AccountInfo> accountInfos = new List<AccountInfo>();
                for (int i = 0; i < this.listView1.Items.Count; i++)
                {
                    if (this.listView1.Items[i].Checked)
                    {
                        ListViewItem listViewItem = this.listView1.Items[i];
                        AccountInfo account = (AccountInfo)listViewItem.Tag;
                        accountInfos.Add(account);
                    }
                }
                if (accountInfos.Count > 0)
                {
                    if (MessageBox.Show(string.Format("确定移动选择的账户到“{0}”分组吗？", this.ddlMoveGroup.Text), "请确定", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        AccountGroupInfo accountGroupInfo = (AccountGroupInfo)htAccountGroupInfo[this.ddlGroup.Text];
                        AccountGroupInfo accountMoveGroupInfo = (AccountGroupInfo)htAccountGroupInfo[this.ddlMoveGroup.Text];
                        for (int i = 0; i < accountInfos.Count; i++)
                        {
                            AccountInfo accountInfo = accountInfos[i];
                            accountInfo.AccountGroupInfo = accountMoveGroupInfo;
                            AddAccountToAccountGroup(accountMoveGroupInfo.Name, accountInfo, true);
                            //if (accountMoveGroupInfo.AccountInfos.Where(a => a.Email == accountInfo.Email).Count() == 0)
                            //    accountMoveGroupInfo.AccountInfos.Add(accountInfo);
                            if (!IsSystemGroupName(this.ddlGroup.Text))
                            {
                                DeleteAccountFromAccountGroup(this.ddlGroup.Text, accountInfo);
                            }

                            DeleteAccountFromAccountGroup(SystemGroup.未分组.ToString(), accountInfo);
                        }
                        Account.EditAccountInfo(accountInfos);
                        this.listView1.Items.Clear();
                        InitListView(accountGroupInfo.AccountInfos);
                        MessageBox.Show(string.Format("移动选择的账户到分组“{0}”完成！", this.ddlMoveGroup.Text));
                        this.ddlMoveGroup.SelectedIndex = 0;
                    }
                    else
                    {
                        this.ddlMoveGroup.SelectedIndex = 0;
                    }
                }
                else
                {
                    MessageBox.Show("尚未选定项！");
                    this.ddlMoveGroup.SelectedIndex = 0;
                }
            }
        }

        private void ddlGroup_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.listView1.Items.Clear();
            IList<AccountInfo> accountInfos = new List<AccountInfo>();
            if (this.ddlGroup.SelectedIndex > 6)
            {
                this.button3.Enabled = true;
                this.button5.Enabled = true;
                this.button9.Enabled = true;
                this.button12.Enabled = true;
                this.button10.Enabled = true;
                this.button8.Enabled = true;
                this.button19.Enabled = true;
                this.button129.Enabled = true; //by sym
                this.button130.Enabled = true; //by sym
            }
            else
            {
                this.button3.Enabled = false;
                this.button5.Enabled = false;
                this.button9.Enabled = false;
                this.button12.Enabled = false;
                this.button10.Enabled = false;
                this.button8.Enabled = false;
                this.button19.Enabled = false;
                this.button129.Enabled = false;//by sym
                this.button130.Enabled = false;//by sym
            }
            AccountGroupInfo accountGroupInfo;
            if (htAccountGroupInfo[this.ddlGroup.Text] == null)
            {
                accountGroupInfo = new AccountGroupInfo
                {
                    Id = Guid.NewGuid(),
                    Name = this.ddlGroup.Text,
                    AccountInfos = new List<AccountInfo>()
                };
                htAccountGroupInfo[this.ddlGroup.Text] = accountGroupInfo;
            }
            else
                accountGroupInfo = (AccountGroupInfo)htAccountGroupInfo[this.ddlGroup.Text];

            accountInfos = accountGroupInfo.AccountInfos ?? new List<AccountInfo>();

            for (int i = accountInfos.Count - 1; i >= 0; i--)
            {
                if (htAccountInfo[accountInfos[i].Email] == null)
                    accountInfos.RemoveAt(i);
            }

            InitListView(accountInfos);
        }

        //添加本地分组
        private void button4_Click(object sender, EventArgs e)
        {
            string newGroupName = this.txtGroupName.Text.Trim();
            if (!string.IsNullOrEmpty(newGroupName) && !IsSystemGroupName(newGroupName))
            {
                if (htAccountGroupInfo[newGroupName] == null)
                {
                    AccountGroupInfo accountGroupInfo = new AccountGroupInfo
                    {
                        Id = Guid.NewGuid(),
                        Name = newGroupName,
                        AccountInfos = new List<AccountInfo>()
                    };
                    AccountGroup.Add(accountGroupInfo);
                    htAccountGroupInfo[accountGroupInfo.Name] = accountGroupInfo;
                    this.ddlGroup.Items.Add(newGroupName);
                    this.ddlMoveGroup.Items.Add(newGroupName);
                    MessageBox.Show("添加分组完成！");
                    this.txtGroupName.Text = string.Empty;
                }
                else
                {
                    MessageBox.Show("该分组名称已存在或不能使用系统分组名称！");
                    this.txtGroupName.Focus();
                }
            }
            else
            {
                MessageBox.Show("分组名称不能为空或者不能使用系统内置分组名称！");
                this.txtGroupName.Focus();
            }
        }

        private void button8_Click(object sender, EventArgs e)
        {
            SetMaster(true);
        }

        //设置/取消主号
        void SetMaster(bool masterFlag)
        {
            IList<AccountInfo> accountInfos = new List<AccountInfo>();
            for (int i = 0; i < this.listView1.Items.Count; i++)
            {
                if (this.listView1.Items[i].Checked)
                {
                    ListViewItem listViewItem = this.listView1.Items[i];
                    AccountInfo account = (AccountInfo)listViewItem.Tag;
                    accountInfos.Add(account);
                }
            }
            if (accountInfos.Count > 0)
            {
                for (int i = 0; i < accountInfos.Count; i++)
                {
                    AccountInfo accountInfo = accountInfos[i];
                    accountInfo.IsMaster = masterFlag;
                    Account.EditAccountInfo(accountInfo);
                    ListViewItem listViewItem = (ListViewItem)accountInfo.Tag;
                    listViewItem.SubItems[7].Text = masterFlag ? "是" : "否";
                    if(masterFlag)
                        AddAccountToAccountGroup(SystemGroup.主号组.ToString(), accountInfo, true);
                    else
                        DeleteAccountFromAccountGroup(SystemGroup.主号组.ToString(), accountInfo);
                }
                MessageBox.Show("设置完成");
            }
            else
            {
                MessageBox.Show("尚未选定项！");
            }
        }

        //日志输出
        delegate void DAppendText(string text);
        public void AppendText(string text)
        {
            int textLength = text.Length;
            this.richTextBox1.AppendText(text);
            this.richTextBox1.Select(textLength, textLength);
            //this.richTextBox1.SelectionColor = Color.Red;
            this.richTextBox1.AppendText("\n");
            this.richTextBox1.ScrollToCaret();
        }

        //小号与主号建立朋友关系
        void AddFriendsWithChildToMaster(object obj)
        {
            this.Invoke(new DAppendText(AppendText), string.Format("[{0}]：开始：小号与主号建立朋友关系\n", DateTime.Now.ToString("HH:mm:ss")));
            IList<AccountInfo> accountInfos = (List<AccountInfo>)obj;

            IList<AccountInfo> masterAccountInfos = new List<AccountInfo>();

            IList<AccountInfo> childAccountInfos = new List<AccountInfo>();

            for (int i = 0; i < accountInfos.Count; i++)
            {
                AccountInfo accountInfo = accountInfos[i];
                if (accountInfo.IsMaster)
                    masterAccountInfos.Add(accountInfo);
                else
                    childAccountInfos.Add(accountInfo);
            }
            Hashtable htMasterVerityChild = new Hashtable();
            //小号验证与主号已经是朋友关系；向主号发送建立好友关系请求
            for (int i = 0; i < childAccountInfos.Count; i++)
            {
                AccountInfo childAccountInfo = childAccountInfos[i];
                IList<AccountInfo> NoFriendMasterAccountInfos = new List<AccountInfo>();
                for (int j = 0; j < masterAccountInfos.Count; j++)
                {
                    AccountInfo masterAccountInfo = masterAccountInfos[j];
                    
                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：验证小号[{1}]与主号[{2}]关系……",
                            DateTime.Now.ToString("HH:mm:ss") ,
                            string.Format("{0},{1}", childAccountInfo.UserInfo.uid, childAccountInfo.UserInfo.real_name),
                            string.Format("{0},{1}", masterAccountInfo.UserInfo.uid, masterAccountInfo.UserInfo.real_name)));

                    //判断小号与主号是否已经是朋友关系
                    if (childAccountInfo.FriendInfos.Where(f => f.uid == masterAccountInfo.UserInfo.uid).Count() == 0)
                    {
                        this.Invoke(new DAppendText(AppendText),
                            string.Format("[{0}]：读取缓存：小号[{1}]与主号[{2}]尚未建立朋友关系",
                                DateTime.Now.ToString("HH:mm:ss") ,
                                string.Format("{0},{1}", childAccountInfo.UserInfo.uid, childAccountInfo.UserInfo.real_name),
                                string.Format("{0},{1}", masterAccountInfo.UserInfo.uid, masterAccountInfo.UserInfo.real_name)));
                        NoFriendMasterAccountInfos.Add(masterAccountInfo);
                    }
                    else
                    {
                        this.Invoke(new DAppendText(AppendText),
                            string.Format("[{0}]：小号[{1}]跟主号[{2}]已经是朋友关系，不需要再建立关系！\n", 
                                DateTime.Now.ToString("HH:mm:ss") ,
                                string.Format("{0},{1}",childAccountInfo.UserInfo.uid, childAccountInfo.UserInfo.real_name),
                                string.Format("{0},{1}",masterAccountInfo.UserInfo.uid,  masterAccountInfo.UserInfo.real_name)));
                    }
                }
                if (NoFriendMasterAccountInfos.Count > 0)
                {
                    User user = new User();
                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：小号[{1}]开始登录系统……",
                            DateTime.Now.ToString("HH:mm:ss") ,
                            string.Format("{0},{1}", childAccountInfo.Email, childAccountInfo.UserInfo.real_name)));
                    if (user.Login(childAccountInfo.Email, childAccountInfo.Password))    //登录
                    {
                        childAccountInfo.FriendInfos = user.GetAllUserInfos();
                        Account.StaticFriends(childAccountInfo);

                        this.Invoke(new DAppendText(AppendText),
                            string.Format("[{0}]：小号[{1}]登录系统成功，并重新获取好友列表，缓存到本地！",
                                DateTime.Now.ToString("HH:mm:ss") ,
                                string.Format("{0},{1}", childAccountInfo.UserInfo.uid, childAccountInfo.UserInfo.real_name)));

                        for (int j = 0; j < NoFriendMasterAccountInfos.Count; j++)
                        {
                            AccountInfo masterAccountInfo = NoFriendMasterAccountInfos[j];
                            if (childAccountInfo.FriendInfos.Where(f => f.uid == masterAccountInfo.UserInfo.uid).Count() == 0)
                            {
                                if (htMasterVerityChild[masterAccountInfo.Email] == null)
                                {
                                    IList<string> childUid = new List<string>();
                                    childUid.Add(childAccountInfo.UserInfo.uid);
                                    htMasterVerityChild[masterAccountInfo.Email] = childUid;
                                }
                                else
                                {
                                    IList<string> childUid = (List<string>)(htMasterVerityChild[masterAccountInfo.Email]);
                                    childUid.Add(childAccountInfo.UserInfo.uid);
                                    htMasterVerityChild[masterAccountInfo.Email] = childUid;
                                }
                                this.Invoke(new DAppendText(AppendText),
                                    string.Format("[{0}]：小号[{1}]开始向主号[{2}]发送添加好友请求……",
                                        DateTime.Now.ToString("HH:mm:ss") ,
                                        string.Format("{0},{1}", childAccountInfo.UserInfo.uid, childAccountInfo.UserInfo.real_name),
                                        string.Format("{0},{1}", masterAccountInfo.UserInfo.uid, masterAccountInfo.UserInfo.real_name)));
                                user.SendAddFriendVerifyRequest(masterAccountInfo.UserInfo.uid);   //发送添加好友验证请求
                                this.Invoke(new DAppendText(AppendText),
                                    string.Format("[{0}]：小号[{1}]向主号[{2}]发送添加好友请求完成！",
                                        DateTime.Now.ToString("HH:mm:ss") ,
                                        string.Format("{0},{1}", childAccountInfo.UserInfo.uid, childAccountInfo.UserInfo.real_name),
                                        string.Format("{0},{1}", masterAccountInfo.UserInfo.uid, masterAccountInfo.UserInfo.real_name)));
                                if (j + 1 < NoFriendMasterAccountInfos.Count)
                                    Thread.Sleep(delayConnect * 1000);
                            }
                            else
                            {
                                this.Invoke(new DAppendText(AppendText),
                                    string.Format("[{0}]：小号[{1}]跟主号[{2}]已经是朋友关系，不需要再建立关系！",
                                        DateTime.Now.ToString("HH:mm:ss") ,
                                        string.Format("{0},{1}", childAccountInfo.UserInfo.uid, childAccountInfo.UserInfo.real_name),
                                        string.Format("{0},{1}", masterAccountInfo.UserInfo.uid, masterAccountInfo.UserInfo.real_name)));
                            }
                        }
                        user.Logout();
                        this.Invoke(new DAppendText(AppendText),
                            string.Format("[{0}]：小号[{1}]退出系统！\n",
                                DateTime.Now.ToString("HH:mm:ss") ,
                                string.Format("{0},{1}", childAccountInfo.UserInfo.uid, childAccountInfo.UserInfo.real_name)));

                    }
                }
            }
            //主号登录，审核请求。
            for (int i = 0; i < masterAccountInfos.Count; i++)
            {
                AccountInfo masterAccountInfo = masterAccountInfos[i];

                if (htMasterVerityChild[masterAccountInfo.Email] != null)
                {
                    IList<string> childUid = (List<string>)(htMasterVerityChild[masterAccountInfo.Email]);
                    if (childUid.Count > 0)
                    {
                        User user = new User();
                        this.Invoke(new DAppendText(AppendText),
                            string.Format("[{0}]：主号[{1}]开始登录系统……",
                                DateTime.Now.ToString("HH:mm:ss") ,
                                string.Format("{0},{1}", masterAccountInfo.UserInfo.uid, masterAccountInfo.UserInfo.real_name)));
                        if (user.Login(masterAccountInfo))
                        {
                            this.Invoke(new DAppendText(AppendText),
                                string.Format("[{0}]：主号[{1}]登录系统成功！",
                                    DateTime.Now.ToString("HH:mm:ss") ,
                                    string.Format("{0},{1}", masterAccountInfo.UserInfo.uid, masterAccountInfo.UserInfo.real_name)));

                            this.Invoke(new DAppendText(AppendText),
                                string.Format("[{0}]：主号[{1}]开始审核小号……",
                                    DateTime.Now.ToString("HH:mm:ss") ,
                                    string.Format("{0},{1}", masterAccountInfo.UserInfo.uid, masterAccountInfo.UserInfo.real_name)));
                            //审核小号请求。
                            user.AgreeFriend(childUid, delayConnect);
                            this.Invoke(new DAppendText(AppendText),
                                string.Format("[{0}]：主号[{1}]审核小号完成！",
                                    DateTime.Now.ToString("HH:mm:ss") ,
                                    string.Format("{0},{1}", masterAccountInfo.UserInfo.uid, masterAccountInfo.UserInfo.real_name)));
                            masterAccountInfo.FriendInfos = user.GetAllUserInfos();
                            Account.StaticFriends(masterAccountInfo);
                            this.Invoke(new DAppendText(AppendText),
                                string.Format("[{0}]：主号[{1}]重新获取好友列表，缓存到本地！",
                                    DateTime.Now.ToString("HH:mm:ss") ,
                                    string.Format("{0},{1}", masterAccountInfo.UserInfo.uid, masterAccountInfo.UserInfo.real_name)));
                            user.Logout();
                            this.Invoke(new DAppendText(AppendText),
                                string.Format("[{0}]：主号[{1}]退出系统！\n",
                                    DateTime.Now.ToString("HH:mm:ss"),
                                    string.Format("{0},{1}", masterAccountInfo.UserInfo.uid, masterAccountInfo.UserInfo.real_name)));
                        }
                    }
                }
            }
            this.Invoke(new DAppendText(AppendText),string.Format("[{0}]：完成：小号与主号朋友关系建立！\n",DateTime.Now.ToString("HH:mm:ss")));
            this.Invoke(new DRestoreControlEnabled(RestoreControlEnabled));
        }

        private void button9_Click(object sender, EventArgs e)
        {
            IList<AccountInfo> accountInfos = new List<AccountInfo>();

            bool existMaster = false;
            bool existChild = false;

            for (int i = 0; i < this.listView1.Items.Count; i++)
            {
                ListViewItem listViewItem = this.listView1.Items[i];
                AccountInfo account = (AccountInfo)listViewItem.Tag;
                if (account.ActiveStatus == ActiveStatus.AlreadyActive || account.ActiveStatus == ActiveStatus.AppForbided)
                {
                    if (account.IsMaster)
                        existMaster = true;
                    else
                        existChild = true;
                    accountInfos.Add(account);
                }
            }
            if (existChild && existMaster)
            {
                this.SetControlDisabled();

                Thread t = new Thread(new ParameterizedThreadStart(AddFriendsWithChildToMaster));
                t.Start(accountInfos);
                lstThread.Add(t);
            }
            else
            {
                MessageBox.Show(string.Format("分组“{0}”中主号或小号不存在！",this.ddlGroup.Text));
            }
        }

        private void button10_Click(object sender, EventArgs e)
        {
            SetMaster(false);
        }

        private void listView1_ColumnClick(object sender, ColumnClickEventArgs e)
        {
            // 检查点击的列是不是现在的排序列.
            if (e.Column == lvwColumnSorter.SortColumn)
            {
                // 重新设置此列的排序方法.
                if (lvwColumnSorter.Order == SortOrder.Ascending)
                {
                    lvwColumnSorter.Order = SortOrder.Descending;
                }
                else
                {
                    lvwColumnSorter.Order = SortOrder.Ascending;
                }
            }
            else
            {
                // 设置排序列，默认为正向排序
                lvwColumnSorter.SortColumn = e.Column;
                lvwColumnSorter.Order = SortOrder.Ascending;
            }

            // 用新的排序方法对ListView排序
            this.listView1.Sort();
        }

        private void Form2_FormClosing(object sender, FormClosingEventArgs e)
        {
            Stop();
        }

        delegate void DStop();
        //结束正在运行中的线程（todo：线程处于阻塞模式时结束不掉）
        public void Stop()
        {
            this.Invoke(new DAppendText(AppendText),
                string.Format("[{0}]：正在中断当前执行线程……",
                    DateTime.Now.ToString("HH:mm:ss")));
            for (int i = 0; i < lstThread.Count; i++)
            {
                if (lstThread[i].IsAlive)
                    lstThread[i].Abort();
            }

            this.Invoke(new DAppendText(AppendText),
                string.Format("[{0}]：中断当前执行线程完成！\n",
                    DateTime.Now.ToString("HH:mm:ss")));

            this.Invoke(new DRestoreControlEnabled(RestoreControlEnabled));
        }

        //生成张炜停车外挂需要的ini文件
        void CreateIniFile(AccountGroupInfo accountGroupInfo, string groupIniDir, string masterTemplateContent, string childTemplateContent)
        {
            try
            {
                if (Directory.Exists(groupIniDir))
                    Directory.Delete(groupIniDir, true);
                Directory.CreateDirectory(groupIniDir);
            }
            catch { }

            IList<AccountInfo> masterAccountInfos = new List<AccountInfo>();

            IList<AccountInfo> childAccountInfos = new List<AccountInfo>();

            for (int i = 0; i < accountGroupInfo.AccountInfos.Count; i++)
            {
                AccountInfo accountInfo = accountGroupInfo.AccountInfos[i];
                if (accountInfo.UserInfo != null)
                {
                    if (accountInfo.IsMaster)
                        masterAccountInfos.Add(accountInfo);
                    else
                        childAccountInfos.Add(accountInfo);
                }
                else
                {
                    AppendText(string.Format("[{0}]：Error：账户[{1}]尚未验证激活状态！",
                           DateTime.Now.ToString("HH:mm:ss"), string.Format("{0}", accountInfo.Email)));
                }
            }

            if (ddlIniTactic.SelectedIndex == 0)
            {
                string masterUids = string.Join(",", GetArray<string>.Get(masterAccountInfos.Select(a => a.UserInfo.uid).ToList()));
                string childUids = string.Join(",", GetArray<string>.Get(childAccountInfos.Select(a => a.UserInfo.uid).ToList()));
                for (int i = 0; i < masterAccountInfos.Count; i++)
                {
                    AccountInfo accountInfo = masterAccountInfos[i];
                    string masterIniContent = masterTemplateContent.Replace("{email}", accountInfo.Email);
                    masterIniContent = masterIniContent.Replace("{password}", accountInfo.Password);
                    masterIniContent = masterIniContent.Replace("{whiteList}", masterUids);//主号停主号 by sym
                    using (StreamWriter sw = new StreamWriter(Path.Combine(groupIniDir, string.Format("{0}_2_master_{1}.ini", accountGroupInfo.Name, i.ToString())), false, Encoding.Default))
                    {
                        sw.Write(masterIniContent);
                    }
                }
                for (int i = 0; i < childAccountInfos.Count; i++)
                {
                    AccountInfo accountInfo = childAccountInfos[i];
                    string childIniContent = childTemplateContent.Replace("{email}", accountInfo.Email);
                    childIniContent = childIniContent.Replace("{password}", accountInfo.Password);
                    childIniContent = childIniContent.Replace("{whiteList}", childUids);//小号尽量停小号 by sym
                    if ( i%2 == 0 )
                    {
                        childIniContent = childIniContent.Replace("{DoParking}", "0");//第一次不停车 by sym
                        childIniContent = childIniContent.Replace("{DoPost}", "1"); //第一次不停车光贴条 by sym
                        childIniContent = childIniContent.Replace("{CarColor}", "0"); //车辆颜色黑色 by sym
                    } else {
                        childIniContent = childIniContent.Replace("{DoParking}", "1");//单号即停车又贴条 by sym
                        childIniContent = childIniContent.Replace("{DoPost}", "1"); //单号即停车又贴条 by sym  
                        childIniContent = childIniContent.Replace("{CarColor}", "255"); //车辆颜色蓝色 by sym
                    }
                    childIniContent = childIniContent.Replace("{NoPostList}", "");
                    using (StreamWriter sw = new StreamWriter(Path.Combine(groupIniDir, string.Format("{0}_1_child_{1}.ini", accountGroupInfo.Name, i.ToString())), false, Encoding.Default))
                    {
                        sw.Write(childIniContent);
                    }
                    //增加一个子循环 by sym
                    if ( i%2 == 0 )
                    {
                        AccountInfo accountInfo1 = childAccountInfos[i];
                        string childIniContent1 = childTemplateContent.Replace("{email}", accountInfo1.Email);
                        childIniContent1 = childIniContent1.Replace("{password}", accountInfo1.Password);
                        childIniContent1 = childIniContent1.Replace("{whiteList}", childUids);
                        childIniContent1 = childIniContent1.Replace("{DoParking}", "1");//第二次光停车 by sym
                        childIniContent1 = childIniContent1.Replace("{DoPost}", "0");//第二次光停车不贴条 by sym
                        childIniContent1 = childIniContent1.Replace("{CarColor}", "0"); //车辆颜色黑色 by sym
                        childIniContent1 = childIniContent1.Replace("{NoPostList}", "");
                        int ii = i + 1;
                        using (StreamWriter sw = new StreamWriter(Path.Combine(groupIniDir, string.Format("{0}_1_child_{1}_0.ini", accountGroupInfo.Name, ii.ToString())), false, Encoding.Default))
                        {
                            sw.Write(childIniContent1);
                        }
                    }
                    // by sym
                
                }
            }
            else if (ddlIniTactic.SelectedIndex == 1)
            {
                IList<AccountInfo> accountInfos = accountGroupInfo.AccountInfos.Where(a => a.UserInfo != null).ToList();
                for (int i = 0; i < accountInfos.Count; i++)
                {
                    AccountInfo accountInfo = accountInfos[i];
                    string whileUid = accountInfos[i == 0 ? (accountInfos.Count - 1) : (i - 1)].UserInfo.uid;
                    string childIniContent = childTemplateContent.Replace("{email}", accountInfo.Email);
                    childIniContent = childIniContent.Replace("{password}", accountInfo.Password);
                    childIniContent = childIniContent.Replace("{whiteList}", 
                        string.Format("{0},1,2",whileUid));
                    childIniContent = childIniContent.Replace("{DoPost}", "0");
                    childIniContent = childIniContent.Replace("{NoPostList}", whileUid);
                    using (StreamWriter sw = new StreamWriter(Path.Combine(groupIniDir, string.Format("{0}_AToBToC_{1}.ini", accountGroupInfo.Name, i.ToString())), false, Encoding.Default))
                    {
                        sw.Write(childIniContent);
                    }
                }
            }

        }

        private void button12_Click(object sender, EventArgs e)
        {
            try
            {
                if (htAccountGroupInfo[this.ddlGroup.Text] != null)
                {
                    if (File.Exists(Common.GetMasterTemplateFile()) && File.Exists(Common.GetChildTemplateFile()))
                    {
                        string masterTemplateContent = string.Empty;
                        string childTemplateContent = string.Empty;

                        using (StreamReader sr = new StreamReader(Common.GetMasterTemplateFile(), Encoding.Default))
                        {
                            masterTemplateContent = sr.ReadToEnd();
                        }

                        using (StreamReader sr = new StreamReader(Common.GetChildTemplateFile(), Encoding.Default))
                        {
                            childTemplateContent = sr.ReadToEnd();
                        }

                        AccountGroupInfo accountGroupInfo = (AccountGroupInfo)htAccountGroupInfo[this.ddlGroup.Text];
                        string groupIniDir = Path.Combine(Common.GetIniPath(), accountGroupInfo.Name);
                        CreateIniFile(accountGroupInfo, groupIniDir, masterTemplateContent, childTemplateContent);
                        MessageBox.Show(string.Format("生成ini文件完成，请到[{0}]下查看！", groupIniDir));
                    }
                    else
                        MessageBox.Show("模板文件不存在！");
                }
                else
                {
                    MessageBox.Show("当前分组下没有账户！");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string newGroupName = this.txtGroupName.Text.Trim();
            if (!string.IsNullOrEmpty(newGroupName) && !IsSystemGroupName(newGroupName))
            {
                AccountGroupInfo accountGroupInfo = (AccountGroupInfo)htAccountGroupInfo[this.ddlGroup.Text];
                accountGroupInfo.Name = this.txtGroupName.Text.Trim();
                if (AccountGroup.Edit(accountGroupInfo))
                {
                    for (int i = 0; i < this.listView1.Items.Count; i++)
                    {
                        ListViewItem listViewItem = this.listView1.Items[i];

                        AccountInfo accountInfo = (AccountInfo)listViewItem.Tag;

                        accountInfo.AccountGroupInfo = accountGroupInfo;

                        listViewItem.SubItems[5].Text = accountGroupInfo.Name;

                        listViewItem.Tag = accountInfo;

                        accountInfo.Tag = listViewItem;

                        htAccountInfo[accountInfo.Email] = accountInfo;
                    }
                    htAccountGroupInfo.Remove(this.ddlGroup.Text);
                    htAccountGroupInfo[this.txtGroupName.Text.Trim()] = accountGroupInfo;
                    this.ddlGroup.Items[this.ddlGroup.SelectedIndex] = this.txtGroupName.Text.Trim();
                    this.ddlGroup.Text = this.txtGroupName.Text.Trim();
                    this.ddlMoveGroup.Items[this.ddlGroup.SelectedIndex - 6] = this.txtGroupName.Text.Trim();
                    MessageBox.Show("编辑完成！");
                }
            }
            else
                MessageBox.Show("分组名称不能为空或者不能使用系统内置分组名称！");
        }

        private void button5_Click(object sender, EventArgs e)
        {
            //MessageBox.Show("继续待做……");
            //return;

            if (this.ddlGroup.SelectedIndex > 6)
            {
                if (MessageBox.Show("确定要删除当前分组吗？\n（删除分组将同时删除分组下账户及缓存的好友列表信息。）", "请确定", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    string groupname = this.ddlGroup.Text;

                    AccountGroupInfo accountGroupInfo = (AccountGroupInfo)htAccountGroupInfo[groupname];
                    for (int i = 0; i < accountGroupInfo.AccountInfos.Count; i++)
                    {
                        AccountInfo accountInfo = accountGroupInfo.AccountInfos[i];
                        htAccountInfo[accountInfo.Email] = null;
                    }

                    AccountGroup.Delete(accountGroupInfo);

                    int selectedIndex = this.ddlGroup.SelectedIndex;

                    this.ddlGroup.Items.RemoveAt(selectedIndex);

                    this.ddlGroup.SelectedIndex = 0;

                    this.ddlMoveGroup.Items.RemoveAt(selectedIndex - 6);

                    MessageBox.Show(string.Format("删除分组：{0} 完成！",groupname));
                }
            }
            else
                MessageBox.Show("系统分组不能删除！");
        }

        private void button11_Click(object sender, EventArgs e)
        {
            IList<AccountInfo> masterAccountInfos = new List<AccountInfo>();

            foreach (DictionaryEntry de in htAccountInfo)
            {
                AccountInfo accountInfo = (AccountInfo)de.Value;
                if (accountInfo.ActiveStatus == ActiveStatus.AlreadyActive && accountInfo.IsMaster)
                    masterAccountInfos.Add(accountInfo);
            }

            if (masterAccountInfos.Count > 1)
            {
                this.SetControlDisabled();

                Thread t = new Thread(new ParameterizedThreadStart(AddFriendsWithSelectedAccounts));
                t.Start(masterAccountInfos);
                lstThread.Add(t);
            }
            else if (masterAccountInfos.Count == 1)
            {
                MessageBox.Show("只设定了一个主号，不能进行主号互加好友！");
            }
            else
            {
                MessageBox.Show("尚未设定主号或所设定主号未激活！");
            }
        }

        void AddFriendsWith1To2And1To3(object obj)
        {
            this.Invoke(new DAppendText(AppendText),
               string.Format("[{0}]：开始好友互加(1+2,1+3,2+4,2+5...)……\n",
                   DateTime.Now.ToString("HH:mm:ss")));

            IList<AccountInfo> accountInfos = (List<AccountInfo>)obj;
            Hashtable htNoFriendAccountInfo = new Hashtable();
            Hashtable htConfirmFriendAccountInfo = new Hashtable();
            Hashtable htReverseConfirmFriendAccountInfo = new Hashtable();
            int floor = 0;
            int floornum = 0;
            for (int i = 0; i < accountInfos.Count; i++)
            {
                AccountInfo sendVeryfyFriendRequestAccountInfo = accountInfos[i];

                for (int j = (i + (int)Math.Pow(2, floor) + floornum); j < ((i + (int)Math.Pow(2, floor) + 2 + floornum) > accountInfos.Count ? accountInfos.Count : (i + (int)Math.Pow(2, floor) + floornum + 2)); j++)
                {
                    AccountInfo confirmVeryfyFriendRequestAccountInfo = accountInfos[j];
                    //通过本地缓存判断是否已经是朋友
                    if (sendVeryfyFriendRequestAccountInfo.FriendInfos.Where(a => a.uid == confirmVeryfyFriendRequestAccountInfo.UserInfo.uid).Count() == 0)
                    {
                        this.Invoke(new DAppendText(AppendText),
                            string.Format("[{0}]：本地缓存判断[{1}]与[{2}]尚未建立好友关系",
                                DateTime.Now.ToString("HH:mm:ss"),
                                string.Format("{0},{1}", sendVeryfyFriendRequestAccountInfo.UserInfo.uid, sendVeryfyFriendRequestAccountInfo.UserInfo.real_name),
                                string.Format("{0},{1}", confirmVeryfyFriendRequestAccountInfo.UserInfo.uid, confirmVeryfyFriendRequestAccountInfo.UserInfo.real_name)
                                ));
                        //本地缓存判断非朋友
                        IList<AccountInfo> noFriendAccountInfos1 = new List<AccountInfo>();
                        if (htNoFriendAccountInfo[sendVeryfyFriendRequestAccountInfo.Email] != null)
                            noFriendAccountInfos1 = (IList<AccountInfo>)htNoFriendAccountInfo[sendVeryfyFriendRequestAccountInfo.Email];
                        noFriendAccountInfos1.Add(confirmVeryfyFriendRequestAccountInfo);
                        htNoFriendAccountInfo[sendVeryfyFriendRequestAccountInfo.Email] = noFriendAccountInfos1;
                    }
                    else
                    {
                        //已经是朋友，不需建立关系
                        this.Invoke(new DAppendText(AppendText),
                            string.Format("[{0}]：本地缓存验证[{1}]与[{2}]已经建立好友关系，不需再建立关系！\n",
                                DateTime.Now.ToString("HH:mm:ss"),
                                string.Format("{0},{1}", sendVeryfyFriendRequestAccountInfo.UserInfo.uid, sendVeryfyFriendRequestAccountInfo.UserInfo.real_name),
                                string.Format("{0},{1}", confirmVeryfyFriendRequestAccountInfo.UserInfo.uid, confirmVeryfyFriendRequestAccountInfo.UserInfo.real_name)
                                ));
                    }
                    //if (i > 0) break;
                    //if (j == accountInfos.Count - 1) break;
                    //j = accountInfos.Count - 2;
                    //break;
                }
                floornum++;
                if (Math.Pow(2, floor) == floornum)
                {
                    floornum = 0;
                    floor++;
                }
                IList<AccountInfo> noFriendAccountInfos = new List<AccountInfo>();
                if (htNoFriendAccountInfo[sendVeryfyFriendRequestAccountInfo.Email] != null)
                    noFriendAccountInfos = (List<AccountInfo>)htNoFriendAccountInfo[sendVeryfyFriendRequestAccountInfo.Email];

                IList<AccountInfo> confirmFriendAccountInfos = new List<AccountInfo>();
                if (htConfirmFriendAccountInfo[sendVeryfyFriendRequestAccountInfo.Email] != null)
                    confirmFriendAccountInfos = (List<AccountInfo>)htConfirmFriendAccountInfo[sendVeryfyFriendRequestAccountInfo.Email];

                if (noFriendAccountInfos.Count > 0 || confirmFriendAccountInfos.Count > 0)
                {
                    User user = new User();

                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：[{1}]开始登录系统……",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", sendVeryfyFriendRequestAccountInfo.Email, sendVeryfyFriendRequestAccountInfo.UserInfo.real_name)));
                    //登录
                    if (user.Login(sendVeryfyFriendRequestAccountInfo))
                    {
                        //登录成功！
                        //重新获取好友列表并缓存到本地
                        sendVeryfyFriendRequestAccountInfo.FriendInfos = user.GetAllUserInfos();
                        Account.StaticFriends(sendVeryfyFriendRequestAccountInfo);
                        this.Invoke(new DAppendText(AppendText),
                            string.Format("[{0}]：[{1}]登录系统成功，并重新获取好友列表，缓存到本地！\n",
                                DateTime.Now.ToString("HH:mm:ss"),
                                string.Format("{0},{1}", sendVeryfyFriendRequestAccountInfo.UserInfo.uid, sendVeryfyFriendRequestAccountInfo.UserInfo.real_name)));
                        //重新验证是否好友关系
                        for (int m = noFriendAccountInfos.Count - 1; m >= 0; m--)
                        {
                            AccountInfo noFriendAccountInfo = noFriendAccountInfos[m];
                            if (sendVeryfyFriendRequestAccountInfo.FriendInfos.Where(a => a.uid == noFriendAccountInfo.UserInfo.uid).Count() > 0)
                            {
                                noFriendAccountInfos.RemoveAt(m);
                                this.Invoke(new DAppendText(AppendText),
                                    string.Format("[{0}]：再次验证[{1}]与[{2}]已经建立好友关系，不需再建立关系！\n",
                                        DateTime.Now.ToString("HH:mm:ss"),
                                        string.Format("{0},{1}", sendVeryfyFriendRequestAccountInfo.UserInfo.uid, sendVeryfyFriendRequestAccountInfo.UserInfo.real_name),
                                        string.Format("{0},{1}", noFriendAccountInfo.UserInfo.uid, noFriendAccountInfo.UserInfo.real_name)
                                        ));
                            }
                        }
                        if (confirmFriendAccountInfos.Count > 0)
                        {
                            this.Invoke(new DAppendText(AppendText),
                                string.Format("[{0}]：[{1}]开始验证好友添加请求……",
                                    DateTime.Now.ToString("HH:mm:ss"),
                                    string.Format("{0},{1}", sendVeryfyFriendRequestAccountInfo.UserInfo.uid, sendVeryfyFriendRequestAccountInfo.UserInfo.real_name)
                                    ));
                            //验证好友添加请求，并返回未验证成功的uid列表
                            IList<string> uids = user.AgreeFriend(confirmFriendAccountInfos.Select(a => a.UserInfo.uid).ToList(), delayConnect);

                            this.Invoke(new DAppendText(AppendText),
                                string.Format("[{0}]：[{1}]验证好友添加请求完成！\n",
                                    DateTime.Now.ToString("HH:mm:ss"),
                                    string.Format("{0},{1}", sendVeryfyFriendRequestAccountInfo.UserInfo.uid, sendVeryfyFriendRequestAccountInfo.UserInfo.real_name)
                                    ));

                            if (uids.Count > 0)
                            {
                                //有未验证成功的uid列表（此种情况产生一般是发送好友添加方好友数目超过了1000）
                                //向uid列表逆向发送添加好友请求
                                this.Invoke(new DAppendText(AppendText),
                                    string.Format("[{0}]：[{1}]有{2}位好友添加请求未处理，将逆向向其发送好友添加请求：",
                                        DateTime.Now.ToString("HH:mm:ss"),
                                        string.Format("{0},{1}", sendVeryfyFriendRequestAccountInfo.UserInfo.uid, sendVeryfyFriendRequestAccountInfo.UserInfo.real_name),
                                        uids.Count.ToString()
                                        ));

                                IList<AccountInfo> noConfirmFriendAccountInfos = confirmFriendAccountInfos.Where(a => GetArray<string>.Get(uids).Contains(a.UserInfo.uid)).ToList();

                                for (int k = 0; k < noConfirmFriendAccountInfos.Count; k++)
                                {
                                    AccountInfo noConfirmFriendAccountInfo = noConfirmFriendAccountInfos[k];
                                    this.Invoke(new DAppendText(AppendText),
                                        string.Format("[{0}]：[{1}]开始向[{2}]发送添加好友请求……",
                                            DateTime.Now.ToString("HH:mm:ss"),
                                            string.Format("{0},{1}", sendVeryfyFriendRequestAccountInfo.UserInfo.uid, sendVeryfyFriendRequestAccountInfo.UserInfo.real_name),
                                            string.Format("{0},{1}", noConfirmFriendAccountInfo.UserInfo.uid, noConfirmFriendAccountInfo.UserInfo.real_name)
                                            ));

                                    //发送添加好友请求
                                    user.SendAddFriendVerifyRequest(noConfirmFriendAccountInfo.UserInfo.uid);

                                    this.Invoke(new DAppendText(AppendText),
                                        string.Format("[{0}]：[{1}]向[{2}]发送添加好友请求完成！",
                                            DateTime.Now.ToString("HH:mm:ss"),
                                            string.Format("{0},{1}", sendVeryfyFriendRequestAccountInfo.UserInfo.uid, sendVeryfyFriendRequestAccountInfo.UserInfo.real_name),
                                            string.Format("{0},{1}", noConfirmFriendAccountInfo.UserInfo.uid, noConfirmFriendAccountInfo.UserInfo.real_name)
                                            ));

                                    IList<AccountInfo> confirmFriendAccountInfos1 = new List<AccountInfo>();
                                    if (htReverseConfirmFriendAccountInfo[noConfirmFriendAccountInfo.Email] != null)
                                        confirmFriendAccountInfos1 = (List<AccountInfo>)htReverseConfirmFriendAccountInfo[noConfirmFriendAccountInfo.Email];
                                    confirmFriendAccountInfos1.Add(sendVeryfyFriendRequestAccountInfo);
                                    htReverseConfirmFriendAccountInfo[noConfirmFriendAccountInfo.Email] = confirmFriendAccountInfos1;
                                    if (k + 1 < noConfirmFriendAccountInfos.Count)
                                        Thread.Sleep(delayConnect * 1000);
                                }

                            }
                        }
                        else
                        {
                            //没有确认添加好友请求
                        }
                        if (noFriendAccountInfos.Count > 0)
                        {
                            for (int m = 0; m < noFriendAccountInfos.Count; m++)
                            {
                                AccountInfo noFriendAccountInfo = noFriendAccountInfos[m];
                                this.Invoke(new DAppendText(AppendText),
                                    string.Format("[{0}]：[{1}]开始向[{2}]发送添加好友请求……",
                                        DateTime.Now.ToString("HH:mm:ss"),
                                        string.Format("{0},{1}", sendVeryfyFriendRequestAccountInfo.UserInfo.uid, sendVeryfyFriendRequestAccountInfo.UserInfo.real_name),
                                        string.Format("{0},{1}", noFriendAccountInfo.UserInfo.uid, noFriendAccountInfo.UserInfo.real_name)
                                        ));
                                //发送添加好友请求
                                user.SendAddFriendVerifyRequest(noFriendAccountInfo.UserInfo.uid);
                                this.Invoke(new DAppendText(AppendText),
                                    string.Format("[{0}]：[{1}]向[{2}]发送添加好友请求完成！",
                                        DateTime.Now.ToString("HH:mm:ss"),
                                        string.Format("{0},{1}", sendVeryfyFriendRequestAccountInfo.UserInfo.uid, sendVeryfyFriendRequestAccountInfo.UserInfo.real_name),
                                        string.Format("{0},{1}", noFriendAccountInfo.UserInfo.uid, noFriendAccountInfo.UserInfo.real_name)
                                        ));
                                IList<AccountInfo> confirmFriendAccountInfos1 = new List<AccountInfo>();
                                if (htConfirmFriendAccountInfo[noFriendAccountInfo.Email] != null)
                                    confirmFriendAccountInfos1 = (List<AccountInfo>)htConfirmFriendAccountInfo[noFriendAccountInfo.Email];
                                confirmFriendAccountInfos1.Add(sendVeryfyFriendRequestAccountInfo);
                                htConfirmFriendAccountInfo[noFriendAccountInfo.Email] = confirmFriendAccountInfos1;
                                if (m + 1 < noFriendAccountInfos.Count)
                                    Thread.Sleep(delayConnect * 1000);
                            }
                        }
                        else
                        {
                            //没有需发送添加好友请求的好友
                        }
                        //退出系统
                        user.Logout();
                        this.Invoke(new DAppendText(AppendText),
                            string.Format("[{0}]：[{1}]成功退出系统！\n",
                                DateTime.Now.ToString("HH:mm:ss"),
                                string.Format("{0},{1}", sendVeryfyFriendRequestAccountInfo.UserInfo.uid, sendVeryfyFriendRequestAccountInfo.UserInfo.real_name)));
                    }
                }
            }

            //存在逆向验证好友情况
            if (htReverseConfirmFriendAccountInfo.Count > 0)
            {
                for (int i = 0; i < accountInfos.Count; i++)
                {
                    AccountInfo reverseConfirmFriendAccountInfo = accountInfos[i];
                    if (htReverseConfirmFriendAccountInfo[reverseConfirmFriendAccountInfo.Email] != null)
                    {
                        this.Invoke(new DAppendText(AppendText),
                            string.Format("[{0}]：[{1}]开始登录系统……",
                                DateTime.Now.ToString("HH:mm:ss"),
                                string.Format("{0},{1}", reverseConfirmFriendAccountInfo.Email, reverseConfirmFriendAccountInfo.UserInfo.real_name)));
                        //登录
                        User user = new User();
                        if (user.Login(reverseConfirmFriendAccountInfo))
                        {
                            //登录成功！
                            //重新获取好友列表并缓存到本地
                            this.Invoke(new DAppendText(AppendText),
                                string.Format("[{0}]：[{1}]登录系统成功\n",
                                    DateTime.Now.ToString("HH:mm:ss"),
                                    string.Format("{0},{1}", reverseConfirmFriendAccountInfo.UserInfo.uid, reverseConfirmFriendAccountInfo.UserInfo.real_name)));

                            IList<AccountInfo> reverseConfirmFriendAccountInfos = (IList<AccountInfo>)htReverseConfirmFriendAccountInfo[reverseConfirmFriendAccountInfo.Email];

                            this.Invoke(new DAppendText(AppendText),
                                string.Format("[{0}]：[{1}]开始验证好友添加请求……",
                                    DateTime.Now.ToString("HH:mm:ss"),
                                    string.Format("{0},{1}", reverseConfirmFriendAccountInfo.UserInfo.uid, reverseConfirmFriendAccountInfo.UserInfo.real_name)
                                    ));
                            //验证好友添加请求
                            user.AgreeFriend(reverseConfirmFriendAccountInfos.Select(a => a.UserInfo.uid).ToList(), delayConnect);

                            this.Invoke(new DAppendText(AppendText),
                                string.Format("[{0}]：[{1}]验证好友添加请求完成！\n",
                                    DateTime.Now.ToString("HH:mm:ss"),
                                    string.Format("{0},{1}", reverseConfirmFriendAccountInfo.UserInfo.uid, reverseConfirmFriendAccountInfo.UserInfo.real_name)
                                    ));
                        }
                    }
                }
            }

            this.Invoke(new DAppendText(AppendText),
                string.Format("[{0}]：完成好友互加(A+B,B+C)！\n",
                    DateTime.Now.ToString("HH:mm:ss")));

            VerifyAccount(accountInfos);

            this.Invoke(new DRestoreControlEnabled(RestoreControlEnabled));
        }


        //选定账户间A+B,B+C建立好友关系
        void AddFriendsWithAToBAndBToC(object obj)
        {
            this.Invoke(new DAppendText(AppendText),
               string.Format("[{0}]：开始好友互加(A+B,B+C)……\n",
                   DateTime.Now.ToString("HH:mm:ss")));

            IList<AccountInfo> accountInfos = (List<AccountInfo>)obj;
            Hashtable htNoFriendAccountInfo = new Hashtable();
            Hashtable htConfirmFriendAccountInfo = new Hashtable();
            Hashtable htReverseConfirmFriendAccountInfo = new Hashtable();
            for (int i = 0; i < accountInfos.Count; i++)
            {
                AccountInfo sendVeryfyFriendRequestAccountInfo = accountInfos[i];

                for (int j = i + 1; j < accountInfos.Count; j++)
                {
                    AccountInfo confirmVeryfyFriendRequestAccountInfo = accountInfos[j];
                    //通过本地缓存判断是否已经是朋友
                    if (sendVeryfyFriendRequestAccountInfo.FriendInfos.Where(a => a.uid == confirmVeryfyFriendRequestAccountInfo.UserInfo.uid).Count() == 0)
                    {
                        this.Invoke(new DAppendText(AppendText),
                            string.Format("[{0}]：本地缓存判断[{1}]与[{2}]尚未建立好友关系",
                                DateTime.Now.ToString("HH:mm:ss"),
                                string.Format("{0},{1}", sendVeryfyFriendRequestAccountInfo.UserInfo.uid, sendVeryfyFriendRequestAccountInfo.UserInfo.real_name),
                                string.Format("{0},{1}", confirmVeryfyFriendRequestAccountInfo.UserInfo.uid, confirmVeryfyFriendRequestAccountInfo.UserInfo.real_name)
                                ));
                        //本地缓存判断非朋友
                        IList<AccountInfo> noFriendAccountInfos1 = new List<AccountInfo>();
                        if (htNoFriendAccountInfo[sendVeryfyFriendRequestAccountInfo.Email] != null)
                            noFriendAccountInfos1 = (IList<AccountInfo>)htNoFriendAccountInfo[sendVeryfyFriendRequestAccountInfo.Email];
                        noFriendAccountInfos1.Add(confirmVeryfyFriendRequestAccountInfo);
                        htNoFriendAccountInfo[sendVeryfyFriendRequestAccountInfo.Email] = noFriendAccountInfos1;
                    }
                    else
                    {
                        //已经是朋友，不需建立关系
                        this.Invoke(new DAppendText(AppendText),
                            string.Format("[{0}]：本地缓存验证[{1}]与[{2}]已经建立好友关系，不需再建立关系！\n",
                                DateTime.Now.ToString("HH:mm:ss"),
                                string.Format("{0},{1}", sendVeryfyFriendRequestAccountInfo.UserInfo.uid, sendVeryfyFriendRequestAccountInfo.UserInfo.real_name),
                                string.Format("{0},{1}", confirmVeryfyFriendRequestAccountInfo.UserInfo.uid, confirmVeryfyFriendRequestAccountInfo.UserInfo.real_name)
                                ));
                    }
                    if (i > 0) break;
                    if (j == accountInfos.Count - 1) break;
                    j = accountInfos.Count - 2;
                    //break;
                }
                IList<AccountInfo> noFriendAccountInfos = new List<AccountInfo>();
                if (htNoFriendAccountInfo[sendVeryfyFriendRequestAccountInfo.Email] != null)
                    noFriendAccountInfos = (List<AccountInfo>)htNoFriendAccountInfo[sendVeryfyFriendRequestAccountInfo.Email];

                IList<AccountInfo> confirmFriendAccountInfos = new List<AccountInfo>();
                if (htConfirmFriendAccountInfo[sendVeryfyFriendRequestAccountInfo.Email] != null)
                    confirmFriendAccountInfos = (List<AccountInfo>)htConfirmFriendAccountInfo[sendVeryfyFriendRequestAccountInfo.Email];

                if (noFriendAccountInfos.Count > 0 || confirmFriendAccountInfos.Count > 0)
                {
                    User user = new User();

                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：[{1}]开始登录系统……",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", sendVeryfyFriendRequestAccountInfo.Email, sendVeryfyFriendRequestAccountInfo.UserInfo.real_name)));
                    //登录
                    if (user.Login(sendVeryfyFriendRequestAccountInfo))
                    {
                        //登录成功！
                        //重新获取好友列表并缓存到本地
                        sendVeryfyFriendRequestAccountInfo.FriendInfos = user.GetAllUserInfos();
                        Account.StaticFriends(sendVeryfyFriendRequestAccountInfo);
                        this.Invoke(new DAppendText(AppendText),
                            string.Format("[{0}]：[{1}]登录系统成功，并重新获取好友列表，缓存到本地！\n",
                                DateTime.Now.ToString("HH:mm:ss"),
                                string.Format("{0},{1}", sendVeryfyFriendRequestAccountInfo.UserInfo.uid, sendVeryfyFriendRequestAccountInfo.UserInfo.real_name)));
                        //重新验证是否好友关系
                        for (int m = noFriendAccountInfos.Count - 1; m >= 0; m--)
                        {
                            AccountInfo noFriendAccountInfo = noFriendAccountInfos[m];
                            if (sendVeryfyFriendRequestAccountInfo.FriendInfos.Where(a => a.uid == noFriendAccountInfo.UserInfo.uid).Count() > 0)
                            {
                                noFriendAccountInfos.RemoveAt(m);
                                this.Invoke(new DAppendText(AppendText),
                                    string.Format("[{0}]：再次验证[{1}]与[{2}]已经建立好友关系，不需再建立关系！\n",
                                        DateTime.Now.ToString("HH:mm:ss"),
                                        string.Format("{0},{1}", sendVeryfyFriendRequestAccountInfo.UserInfo.uid, sendVeryfyFriendRequestAccountInfo.UserInfo.real_name),
                                        string.Format("{0},{1}", noFriendAccountInfo.UserInfo.uid, noFriendAccountInfo.UserInfo.real_name)
                                        ));
                            }
                        }
                        if (confirmFriendAccountInfos.Count > 0)
                        {
                            this.Invoke(new DAppendText(AppendText),
                                string.Format("[{0}]：[{1}]开始验证好友添加请求……",
                                    DateTime.Now.ToString("HH:mm:ss"),
                                    string.Format("{0},{1}", sendVeryfyFriendRequestAccountInfo.UserInfo.uid, sendVeryfyFriendRequestAccountInfo.UserInfo.real_name)
                                    ));
                            //验证好友添加请求，并返回未验证成功的uid列表
                            IList<string> uids = user.AgreeFriend(confirmFriendAccountInfos.Select(a => a.UserInfo.uid).ToList(), delayConnect);
                            
                            this.Invoke(new DAppendText(AppendText),
                                string.Format("[{0}]：[{1}]验证好友添加请求完成！\n",
                                    DateTime.Now.ToString("HH:mm:ss"),
                                    string.Format("{0},{1}", sendVeryfyFriendRequestAccountInfo.UserInfo.uid, sendVeryfyFriendRequestAccountInfo.UserInfo.real_name)
                                    ));

                            if (uids.Count > 0)
                            {
                                //有未验证成功的uid列表（此种情况产生一般是发送好友添加方好友数目超过了1000）
                                //向uid列表逆向发送添加好友请求
                                this.Invoke(new DAppendText(AppendText),
                                    string.Format("[{0}]：[{1}]有{2}位好友添加请求未处理，将逆向向其发送好友添加请求：",
                                        DateTime.Now.ToString("HH:mm:ss"),
                                        string.Format("{0},{1}", sendVeryfyFriendRequestAccountInfo.UserInfo.uid, sendVeryfyFriendRequestAccountInfo.UserInfo.real_name),
                                        uids.Count.ToString()
                                        ));

                                IList<AccountInfo> noConfirmFriendAccountInfos = confirmFriendAccountInfos.Where(a => GetArray<string>.Get(uids).Contains(a.UserInfo.uid)).ToList();

                                for (int k = 0; k < noConfirmFriendAccountInfos.Count; k++)
                                {
                                    AccountInfo noConfirmFriendAccountInfo = noConfirmFriendAccountInfos[k];
                                    this.Invoke(new DAppendText(AppendText),
                                        string.Format("[{0}]：[{1}]开始向[{2}]发送添加好友请求……",
                                            DateTime.Now.ToString("HH:mm:ss"),
                                            string.Format("{0},{1}", sendVeryfyFriendRequestAccountInfo.UserInfo.uid, sendVeryfyFriendRequestAccountInfo.UserInfo.real_name),
                                            string.Format("{0},{1}", noConfirmFriendAccountInfo.UserInfo.uid, noConfirmFriendAccountInfo.UserInfo.real_name)
                                            ));

                                    //发送添加好友请求
                                    user.SendAddFriendVerifyRequest(noConfirmFriendAccountInfo.UserInfo.uid);

                                    this.Invoke(new DAppendText(AppendText),
                                        string.Format("[{0}]：[{1}]向[{2}]发送添加好友请求完成！",
                                            DateTime.Now.ToString("HH:mm:ss"),
                                            string.Format("{0},{1}", sendVeryfyFriendRequestAccountInfo.UserInfo.uid, sendVeryfyFriendRequestAccountInfo.UserInfo.real_name),
                                            string.Format("{0},{1}", noConfirmFriendAccountInfo.UserInfo.uid, noConfirmFriendAccountInfo.UserInfo.real_name)
                                            ));

                                    IList<AccountInfo> confirmFriendAccountInfos1 = new List<AccountInfo>();
                                    if (htReverseConfirmFriendAccountInfo[noConfirmFriendAccountInfo.Email] != null)
                                        confirmFriendAccountInfos1 = (List<AccountInfo>)htReverseConfirmFriendAccountInfo[noConfirmFriendAccountInfo.Email];
                                    confirmFriendAccountInfos1.Add(sendVeryfyFriendRequestAccountInfo);
                                    htReverseConfirmFriendAccountInfo[noConfirmFriendAccountInfo.Email] = confirmFriendAccountInfos1;
                                    if (k + 1 < noConfirmFriendAccountInfos.Count)
                                        Thread.Sleep(delayConnect * 1000);
                                }

                            }
                        }
                        else
                        {
                            //没有确认添加好友请求
                        }
                        if (noFriendAccountInfos.Count > 0)
                        {
                            for (int m = 0; m < noFriendAccountInfos.Count; m++)
                            {
                                AccountInfo noFriendAccountInfo = noFriendAccountInfos[m];
                                this.Invoke(new DAppendText(AppendText),
                                    string.Format("[{0}]：[{1}]开始向[{2}]发送添加好友请求……",
                                        DateTime.Now.ToString("HH:mm:ss"),
                                        string.Format("{0},{1}", sendVeryfyFriendRequestAccountInfo.UserInfo.uid, sendVeryfyFriendRequestAccountInfo.UserInfo.real_name),
                                        string.Format("{0},{1}", noFriendAccountInfo.UserInfo.uid, noFriendAccountInfo.UserInfo.real_name)
                                        ));
                                //发送添加好友请求
                                user.SendAddFriendVerifyRequest(noFriendAccountInfo.UserInfo.uid);
                                this.Invoke(new DAppendText(AppendText),
                                    string.Format("[{0}]：[{1}]向[{2}]发送添加好友请求完成！",
                                        DateTime.Now.ToString("HH:mm:ss"),
                                        string.Format("{0},{1}", sendVeryfyFriendRequestAccountInfo.UserInfo.uid, sendVeryfyFriendRequestAccountInfo.UserInfo.real_name),
                                        string.Format("{0},{1}", noFriendAccountInfo.UserInfo.uid, noFriendAccountInfo.UserInfo.real_name)
                                        ));
                                IList<AccountInfo> confirmFriendAccountInfos1 = new List<AccountInfo>();
                                if (htConfirmFriendAccountInfo[noFriendAccountInfo.Email] != null)
                                    confirmFriendAccountInfos1 = (List<AccountInfo>)htConfirmFriendAccountInfo[noFriendAccountInfo.Email];
                                confirmFriendAccountInfos1.Add(sendVeryfyFriendRequestAccountInfo);
                                htConfirmFriendAccountInfo[noFriendAccountInfo.Email] = confirmFriendAccountInfos1;
                                if (m + 1 < noFriendAccountInfos.Count)
                                    Thread.Sleep(delayConnect * 1000);
                            }
                        }
                        else
                        {
                            //没有需发送添加好友请求的好友
                        }
                        //退出系统
                        user.Logout();
                        this.Invoke(new DAppendText(AppendText),
                            string.Format("[{0}]：[{1}]成功退出系统！\n",
                                DateTime.Now.ToString("HH:mm:ss"),
                                string.Format("{0},{1}", sendVeryfyFriendRequestAccountInfo.UserInfo.uid, sendVeryfyFriendRequestAccountInfo.UserInfo.real_name)));
                    }
                }
            }

            //存在逆向验证好友情况
            if (htReverseConfirmFriendAccountInfo.Count > 0)
            {
                for (int i = 0; i < accountInfos.Count; i++)
                {
                    AccountInfo reverseConfirmFriendAccountInfo = accountInfos[i];
                    if (htReverseConfirmFriendAccountInfo[reverseConfirmFriendAccountInfo.Email] != null)
                    {
                        this.Invoke(new DAppendText(AppendText),
                            string.Format("[{0}]：[{1}]开始登录系统……",
                                DateTime.Now.ToString("HH:mm:ss"),
                                string.Format("{0},{1}", reverseConfirmFriendAccountInfo.Email, reverseConfirmFriendAccountInfo.UserInfo.real_name)));
                        //登录
                        User user = new User();
                        if (user.Login(reverseConfirmFriendAccountInfo))
                        {
                            //登录成功！
                            //重新获取好友列表并缓存到本地
                            this.Invoke(new DAppendText(AppendText),
                                string.Format("[{0}]：[{1}]登录系统成功\n",
                                    DateTime.Now.ToString("HH:mm:ss"),
                                    string.Format("{0},{1}", reverseConfirmFriendAccountInfo.UserInfo.uid, reverseConfirmFriendAccountInfo.UserInfo.real_name)));

                            IList<AccountInfo> reverseConfirmFriendAccountInfos = (IList<AccountInfo>)htReverseConfirmFriendAccountInfo[reverseConfirmFriendAccountInfo.Email];

                            this.Invoke(new DAppendText(AppendText),
                                string.Format("[{0}]：[{1}]开始验证好友添加请求……",
                                    DateTime.Now.ToString("HH:mm:ss"),
                                    string.Format("{0},{1}", reverseConfirmFriendAccountInfo.UserInfo.uid, reverseConfirmFriendAccountInfo.UserInfo.real_name)
                                    ));
                            //验证好友添加请求
                            user.AgreeFriend(reverseConfirmFriendAccountInfos.Select(a => a.UserInfo.uid).ToList(), delayConnect);

                            this.Invoke(new DAppendText(AppendText),
                                string.Format("[{0}]：[{1}]验证好友添加请求完成！\n",
                                    DateTime.Now.ToString("HH:mm:ss"),
                                    string.Format("{0},{1}", reverseConfirmFriendAccountInfo.UserInfo.uid, reverseConfirmFriendAccountInfo.UserInfo.real_name)
                                    ));
                        }
                    }
                }
            }

            this.Invoke(new DAppendText(AppendText),
                string.Format("[{0}]：完成好友互加(A+B,B+C)！\n",
                    DateTime.Now.ToString("HH:mm:ss")));

            VerifyAccount(accountInfos);

            this.Invoke(new DRestoreControlEnabled(RestoreControlEnabled));
        }

        //选定账户间建立好友关系
        void AddFriendsWithSelectedAccounts(object obj)
        {
            this.Invoke(new DAppendText(AppendText),
                string.Format("[{0}]：开始好友互加……\n",
                    DateTime.Now.ToString("HH:mm:ss")));

            IList<AccountInfo> masterAccountInfos = (List<AccountInfo>)obj;
            Hashtable htNoFriendAccountInfo = new Hashtable();
            Hashtable htConfirmFriendAccountInfo = new Hashtable();
            Hashtable htReverseConfirmFriendAccountInfo = new Hashtable();

            for (int i = 0; i < masterAccountInfos.Count; i++)
            {
                AccountInfo sendVeryfyFriendRequestMasterAccountInfo = masterAccountInfos[i];

                for (int j = i+1; j < masterAccountInfos.Count; j++)
                {
                    AccountInfo confirmVeryfyFriendRequestMasterAccountInfo = masterAccountInfos[j];
                    //通过本地缓存判断是否已经是朋友
                    if (sendVeryfyFriendRequestMasterAccountInfo.FriendInfos.Where(a => a.uid == confirmVeryfyFriendRequestMasterAccountInfo.UserInfo.uid).Count() == 0)
                    {
                        this.Invoke(new DAppendText(AppendText),
                            string.Format("[{0}]：本地缓存判断[{1}]与[{2}]尚未建立好友关系",
                                DateTime.Now.ToString("HH:mm:ss"),
                                string.Format("{0},{1}", sendVeryfyFriendRequestMasterAccountInfo.UserInfo.uid, sendVeryfyFriendRequestMasterAccountInfo.UserInfo.real_name),
                                string.Format("{0},{1}", confirmVeryfyFriendRequestMasterAccountInfo.UserInfo.uid, confirmVeryfyFriendRequestMasterAccountInfo.UserInfo.real_name)
                                ));
                        //本地缓存判断非朋友
                        IList<AccountInfo> noFriendAccountInfos1 = new List<AccountInfo>();
                        if (htNoFriendAccountInfo[sendVeryfyFriendRequestMasterAccountInfo.Email] != null)
                            noFriendAccountInfos1 = (IList<AccountInfo>)htNoFriendAccountInfo[sendVeryfyFriendRequestMasterAccountInfo.Email];
                        noFriendAccountInfos1.Add(confirmVeryfyFriendRequestMasterAccountInfo);
                        htNoFriendAccountInfo[sendVeryfyFriendRequestMasterAccountInfo.Email] = noFriendAccountInfos1;
                    }
                    else
                    {
                        //已经是朋友，不需建立关系
                        this.Invoke(new DAppendText(AppendText),
                            string.Format("[{0}]：本地缓存验证[{1}]与[{2}]已经建立好友关系，不需再建立关系！\n",
                                DateTime.Now.ToString("HH:mm:ss"),
                                string.Format("{0},{1}", sendVeryfyFriendRequestMasterAccountInfo.UserInfo.uid, sendVeryfyFriendRequestMasterAccountInfo.UserInfo.real_name),
                                string.Format("{0},{1}", confirmVeryfyFriendRequestMasterAccountInfo.UserInfo.uid, confirmVeryfyFriendRequestMasterAccountInfo.UserInfo.real_name)
                                ));
                    }
                }
                IList<AccountInfo> noFriendAccountInfos = new List<AccountInfo>();
                if (htNoFriendAccountInfo[sendVeryfyFriendRequestMasterAccountInfo.Email] != null)
                    noFriendAccountInfos = (List<AccountInfo>)htNoFriendAccountInfo[sendVeryfyFriendRequestMasterAccountInfo.Email];

                IList<AccountInfo> confirmFriendAccountInfos = new List<AccountInfo>();
                if(htConfirmFriendAccountInfo[sendVeryfyFriendRequestMasterAccountInfo.Email] != null)
                    confirmFriendAccountInfos = (List<AccountInfo>)htConfirmFriendAccountInfo[sendVeryfyFriendRequestMasterAccountInfo.Email] ;

                if (noFriendAccountInfos.Count > 0 || confirmFriendAccountInfos.Count > 0)
                {
                    User user = new User();

                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：[{1}]开始登录系统……",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", sendVeryfyFriendRequestMasterAccountInfo.Email, sendVeryfyFriendRequestMasterAccountInfo.UserInfo.real_name)));
                    //登录
                    if (user.Login(sendVeryfyFriendRequestMasterAccountInfo))
                    {
                        //登录成功！
                        //重新获取好友列表并缓存到本地
                        sendVeryfyFriendRequestMasterAccountInfo.FriendInfos = user.GetAllUserInfos();
                        Account.StaticFriends(sendVeryfyFriendRequestMasterAccountInfo);
                        this.Invoke(new DAppendText(AppendText),
                            string.Format("[{0}]：[{1}]登录系统成功，并重新获取好友列表，缓存到本地！\n",
                                DateTime.Now.ToString("HH:mm:ss"),
                                string.Format("{0},{1}", sendVeryfyFriendRequestMasterAccountInfo.UserInfo.uid, sendVeryfyFriendRequestMasterAccountInfo.UserInfo.real_name)));
                        //重新验证是否好友关系
                        for (int m = noFriendAccountInfos.Count - 1; m >= 0; m--)
                        {
                            AccountInfo noFriendAccountInfo = noFriendAccountInfos[m];
                            if (sendVeryfyFriendRequestMasterAccountInfo.FriendInfos.Where(a => a.uid == noFriendAccountInfo.UserInfo.uid).Count() > 0)
                            {
                                noFriendAccountInfos.RemoveAt(m);
                                this.Invoke(new DAppendText(AppendText),
                                    string.Format("[{0}]：再次验证[{1}]与[{2}]已经建立好友关系，不需再建立关系！\n",
                                        DateTime.Now.ToString("HH:mm:ss"),
                                        string.Format("{0},{1}", sendVeryfyFriendRequestMasterAccountInfo.UserInfo.uid, sendVeryfyFriendRequestMasterAccountInfo.UserInfo.real_name),
                                        string.Format("{0},{1}", noFriendAccountInfo.UserInfo.uid, noFriendAccountInfo.UserInfo.real_name)
                                        ));
                            }
                        }
                        if (confirmFriendAccountInfos.Count > 0)
                        {
                            this.Invoke(new DAppendText(AppendText),
                                string.Format("[{0}]：[{1}]开始验证好友添加请求……",
                                    DateTime.Now.ToString("HH:mm:ss"),
                                    string.Format("{0},{1}", sendVeryfyFriendRequestMasterAccountInfo.UserInfo.uid, sendVeryfyFriendRequestMasterAccountInfo.UserInfo.real_name)
                                    ));
                            //验证好友添加请求，并返回未验证成功的uid列表
                            IList<string> uids = user.AgreeFriend(confirmFriendAccountInfos.Select(a => a.UserInfo.uid).ToList(), delayConnect);

                            this.Invoke(new DAppendText(AppendText),
                                string.Format("[{0}]：[{1}]验证好友添加请求完成！\n",
                                    DateTime.Now.ToString("HH:mm:ss"),
                                    string.Format("{0},{1}", sendVeryfyFriendRequestMasterAccountInfo.UserInfo.uid, sendVeryfyFriendRequestMasterAccountInfo.UserInfo.real_name)
                                    ));


                            if (uids.Count > 0)
                            {
                                //有未验证成功的uid列表（此种情况产生一般是发送好友添加方好友数目超过了1000）
                                //向uid列表逆向发送添加好友请求
                                this.Invoke(new DAppendText(AppendText),
                                    string.Format("[{0}]：[{1}]有{2}位好友添加请求未处理，将逆向向其发送好友添加请求：",
                                        DateTime.Now.ToString("HH:mm:ss"),
                                        string.Format("{0},{1}", sendVeryfyFriendRequestMasterAccountInfo.UserInfo.uid, sendVeryfyFriendRequestMasterAccountInfo.UserInfo.real_name),
                                        uids.Count.ToString()
                                        ));

                                IList<AccountInfo> noConfirmFriendAccountInfos = confirmFriendAccountInfos.Where(a => GetArray<string>.Get(uids).Contains(a.UserInfo.uid)).ToList();

                                for (int k = 0; k < noConfirmFriendAccountInfos.Count; k++)
                                {
                                    AccountInfo noConfirmFriendAccountInfo = noConfirmFriendAccountInfos[k];
                                    this.Invoke(new DAppendText(AppendText),
                                        string.Format("[{0}]：[{1}]开始向[{2}]发送添加好友请求……",
                                            DateTime.Now.ToString("HH:mm:ss"),
                                            string.Format("{0},{1}", sendVeryfyFriendRequestMasterAccountInfo.UserInfo.uid, sendVeryfyFriendRequestMasterAccountInfo.UserInfo.real_name),
                                            string.Format("{0},{1}", noConfirmFriendAccountInfo.UserInfo.uid, noConfirmFriendAccountInfo.UserInfo.real_name)
                                            ));

                                    //发送添加好友请求
                                    user.SendAddFriendVerifyRequest(noConfirmFriendAccountInfo.UserInfo.uid);

                                    this.Invoke(new DAppendText(AppendText),
                                        string.Format("[{0}]：[{1}]向[{2}]发送添加好友请求完成！",
                                            DateTime.Now.ToString("HH:mm:ss"),
                                            string.Format("{0},{1}", sendVeryfyFriendRequestMasterAccountInfo.UserInfo.uid, sendVeryfyFriendRequestMasterAccountInfo.UserInfo.real_name),
                                            string.Format("{0},{1}", noConfirmFriendAccountInfo.UserInfo.uid, noConfirmFriendAccountInfo.UserInfo.real_name)
                                            ));

                                    IList<AccountInfo> confirmFriendAccountInfos1 = new List<AccountInfo>();
                                    if (htReverseConfirmFriendAccountInfo[noConfirmFriendAccountInfo.Email] != null)
                                        confirmFriendAccountInfos1 = (List<AccountInfo>)htReverseConfirmFriendAccountInfo[noConfirmFriendAccountInfo.Email];
                                    confirmFriendAccountInfos1.Add(sendVeryfyFriendRequestMasterAccountInfo);
                                    htReverseConfirmFriendAccountInfo[noConfirmFriendAccountInfo.Email] = confirmFriendAccountInfos1;
                                    if (k + 1 < noConfirmFriendAccountInfos.Count)
                                        Thread.Sleep(delayConnect * 1000);
                                }

                            }

                        }
                        else
                        {
                            //没有确认添加好友请求
                        }
                        if (noFriendAccountInfos.Count > 0)
                        {
                            for (int m = 0; m < noFriendAccountInfos.Count; m++)
                            {
                                AccountInfo noFriendAccountInfo = noFriendAccountInfos[m];
                                this.Invoke(new DAppendText(AppendText),
                                    string.Format("[{0}]：[{1}]开始向[{2}]发送添加好友请求……",
                                        DateTime.Now.ToString("HH:mm:ss"),
                                        string.Format("{0},{1}", sendVeryfyFriendRequestMasterAccountInfo.UserInfo.uid, sendVeryfyFriendRequestMasterAccountInfo.UserInfo.real_name),
                                        string.Format("{0},{1}", noFriendAccountInfo.UserInfo.uid, noFriendAccountInfo.UserInfo.real_name)
                                        ));
                                //发送添加好友请求
                                user.SendAddFriendVerifyRequest(noFriendAccountInfo.UserInfo.uid);
                                this.Invoke(new DAppendText(AppendText),
                                    string.Format("[{0}]：[{1}]向[{2}]发送添加好友请求完成！",
                                        DateTime.Now.ToString("HH:mm:ss"),
                                        string.Format("{0},{1}", sendVeryfyFriendRequestMasterAccountInfo.UserInfo.uid, sendVeryfyFriendRequestMasterAccountInfo.UserInfo.real_name),
                                        string.Format("{0},{1}", noFriendAccountInfo.UserInfo.uid, noFriendAccountInfo.UserInfo.real_name)
                                        ));
                                IList<AccountInfo> confirmFriendAccountInfos1 = new List<AccountInfo>();
                                if (htConfirmFriendAccountInfo[noFriendAccountInfo.Email] != null)
                                    confirmFriendAccountInfos1 = (List<AccountInfo>)htConfirmFriendAccountInfo[noFriendAccountInfo.Email];
                                confirmFriendAccountInfos1.Add(sendVeryfyFriendRequestMasterAccountInfo);
                                htConfirmFriendAccountInfo[noFriendAccountInfo.Email] = confirmFriendAccountInfos1;
                                if (m + 1 < noFriendAccountInfos.Count)
                                    Thread.Sleep(delayConnect * 1000);
                            }
                        }
                        else
                        {
                            //没有需发送添加好友请求的好友
                        }
                        //退出系统
                        user.Logout();
                        this.Invoke(new DAppendText(AppendText),
                            string.Format("[{0}]：[{1}]成功退出系统！\n",
                                DateTime.Now.ToString("HH:mm:ss"),
                                string.Format("{0},{1}", sendVeryfyFriendRequestMasterAccountInfo.UserInfo.uid, sendVeryfyFriendRequestMasterAccountInfo.UserInfo.real_name)));
                    }
                }

            }


            //存在逆向验证好友情况
            if (htReverseConfirmFriendAccountInfo.Count > 0)
            {
                for (int i = 0; i < masterAccountInfos.Count; i++)
                {
                    AccountInfo reverseConfirmFriendAccountInfo = masterAccountInfos[i];
                    if (htReverseConfirmFriendAccountInfo[reverseConfirmFriendAccountInfo.Email] != null)
                    {
                        this.Invoke(new DAppendText(AppendText),
                            string.Format("[{0}]：[{1}]开始登录系统……",
                                DateTime.Now.ToString("HH:mm:ss"),
                                string.Format("{0},{1}", reverseConfirmFriendAccountInfo.Email, reverseConfirmFriendAccountInfo.UserInfo.real_name)));
                        //登录
                        User user = new User();
                        if (user.Login(reverseConfirmFriendAccountInfo))
                        {
                            //登录成功！
                            //重新获取好友列表并缓存到本地
                            this.Invoke(new DAppendText(AppendText),
                                string.Format("[{0}]：[{1}]登录系统成功\n",
                                    DateTime.Now.ToString("HH:mm:ss"),
                                    string.Format("{0},{1}", reverseConfirmFriendAccountInfo.UserInfo.uid, reverseConfirmFriendAccountInfo.UserInfo.real_name)));

                            IList<AccountInfo> reverseConfirmFriendAccountInfos = (IList<AccountInfo>)htReverseConfirmFriendAccountInfo[reverseConfirmFriendAccountInfo.Email];

                            this.Invoke(new DAppendText(AppendText),
                                string.Format("[{0}]：[{1}]开始验证好友添加请求……",
                                    DateTime.Now.ToString("HH:mm:ss"),
                                    string.Format("{0},{1}", reverseConfirmFriendAccountInfo.UserInfo.uid, reverseConfirmFriendAccountInfo.UserInfo.real_name)
                                    ));
                            //验证好友添加请求
                            user.AgreeFriend(reverseConfirmFriendAccountInfos.Select(a => a.UserInfo.uid).ToList(), delayConnect);

                            this.Invoke(new DAppendText(AppendText),
                                string.Format("[{0}]：[{1}]验证好友添加请求完成！\n",
                                    DateTime.Now.ToString("HH:mm:ss"),
                                    string.Format("{0},{1}", reverseConfirmFriendAccountInfo.UserInfo.uid, reverseConfirmFriendAccountInfo.UserInfo.real_name)
                                    ));
                        }
                    }
                }
            }

            this.Invoke(new DAppendText(AppendText),
                string.Format("[{0}]：完成好友互加！\n",
                    DateTime.Now.ToString("HH:mm:ss")));
            this.Invoke(new DRestoreControlEnabled(RestoreControlEnabled));

        }

        private void button13_Click(object sender, EventArgs e)
        {
            string message = "accounts.txt格式为：\n";
            message += "email password（换行）\n";
            message += "email password（换行）\n";
            message += "......................\n";
            message += "email password\n";
            message += "本文件也可由本人做的另一工具-开心网批量马甲辅助注册工具生成。";

            MessageBox.Show(message);
        }

        private void button14_Click(object sender, EventArgs e)
        {
            if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                this.textBox1.Text = this.openFileDialog1.FileName;
            }
        }

        private void button15_Click(object sender, EventArgs e)
        {
            this.richTextBox1.Clear();
        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count > 0)
            {
                ListViewItem listViewItem = this.listView1.SelectedItems[0];
                AccountInfo accountInfo = (AccountInfo)listViewItem.Tag;
                this.textBox3.Text = accountInfo.Email;
                this.textBox4.Text = accountInfo.Password;
            }
            else
            {
                this.textBox3.Text = string.Empty;
                this.textBox4.Text = string.Empty;
            }
        }

        private void button16_Click(object sender, EventArgs e)
        {
            if (File.Exists(Common.GetMasterTemplateFile()) && File.Exists(Common.GetChildTemplateFile()))
            {
                string masterTemplateContent = string.Empty;
                string childTemplateContent = string.Empty;

                AppendText(string.Format("[{0}]：开始所有分组生成停车ini文件……\n",
                        DateTime.Now.ToString("HH:mm:ss")));

                AppendText(string.Format("[{0}]：读取主号停车配置文件模板",DateTime.Now.ToString("HH:mm:ss")));

                using (StreamReader sr = new StreamReader(Common.GetMasterTemplateFile(), Encoding.Default))
                {
                    masterTemplateContent = sr.ReadToEnd();
                }

                AppendText(string.Format("[{0}]：读取小号停车配置文件模板\n",DateTime.Now.ToString("HH:mm:ss")));

                using (StreamReader sr = new StreamReader(Common.GetChildTemplateFile(), Encoding.Default))
                {
                    childTemplateContent = sr.ReadToEnd();
                }

                int i = 0;
                foreach (DictionaryEntry de in htAccountGroupInfo)
                {
                    string groupName = de.Key.ToString();
                    if (!IsSystemGroupName(groupName))
                    {
                        AccountGroupInfo accountGroupInfo = (AccountGroupInfo)de.Value;
                        accountGroupInfo.AccountInfos = accountGroupInfo.AccountInfos ?? new List<AccountInfo>();
                        string groupIniDir = Path.Combine(Common.GetIniPath(), accountGroupInfo.Name);
                        if (accountGroupInfo.AccountInfos.Count > 0)
                        {
                            ++i;
                            CreateIniFile(accountGroupInfo, groupIniDir, masterTemplateContent, childTemplateContent);
                            AppendText(string.Format("[{0}]：分组[{1}]生成ini完成！", DateTime.Now.ToString("HH:mm:ss"), accountGroupInfo.Name));
                        }
                        else
                        {
                            AppendText(string.Format("[{0}]：分组[{1}]内没数据！", DateTime.Now.ToString("HH:mm:ss"), accountGroupInfo.Name));
                        }
                    }
                }
                AppendText(string.Format("{0}[{1}]：完成！共生成{2}组ini文件，请到[{3}]下查看！\n",i> 0 ? "\n" : string.Empty, DateTime.Now.ToString("HH:mm:ss"), i.ToString(), Common.GetIniPath()));
                MessageBox.Show(string.Format("完成！共生成{0}组ini文件，请到[{1}]下查看！", i.ToString(), Common.GetIniPath()));
            }
            else
            {
                MessageBox.Show("模板文件不存在！");
            }
        }

        private void listView1_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (this.listView1.SelectedItems.Count > 0)
                {
                    ListViewItem selectedListViewItem = this.listView1.SelectedItems[0];
                    AccountInfo accountInfo = (AccountInfo)selectedListViewItem.Tag;
                    if (accountInfo.ActiveStatus == ActiveStatus.AlreadyActive || accountInfo.ActiveStatus == ActiveStatus.AppForbided)
                    {
                        用他的邀请码提交注册ToolStripMenuItem.Enabled = true;
                        好友管理ToolStripMenuItem.Enabled = true;
                        我的车ToolStripMenuItem.Enabled = true;
                        打开浏览器登录ToolStripMenuItem.Enabled = true;
                        验证好友添加请求ToolStripMenuItem.Enabled = true;
                        拉力赛ToolStripMenuItem.Enabled = true;
                        if (accountInfo.ActiveStatus == ActiveStatus.AppForbided)
                        {
                            我的车ToolStripMenuItem.Enabled = false;
                            拉力赛ToolStripMenuItem.Enabled = false;
                        }
                    }
                    else
                    {
                        用他的邀请码提交注册ToolStripMenuItem.Enabled = false;
                        好友管理ToolStripMenuItem.Enabled = false;
                        我的车ToolStripMenuItem.Enabled = false;
                        打开浏览器登录ToolStripMenuItem.Enabled = false;
                        验证好友添加请求ToolStripMenuItem.Enabled = false;
                        拉力赛ToolStripMenuItem.Enabled = false;
                    }
                }
                this.contextMenuStrip1.Show((Control)sender, new Point(e.X, e.Y));
            }
        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                ImportAccountFile(this.openFileDialog1.FileName);
            }
        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count > 0)
            {
                ListViewItem listViewItem = this.listView1.SelectedItems[0];
                AccountInfo accountInfo = (AccountInfo)listViewItem.Tag;
                string password = Interaction.InputBox("请输入密码", "密码输入", accountInfo.Password, 100, 0);
                if (!string.IsNullOrEmpty(password))
                {
                    accountInfo.Password = password;
                    Account.EditAccountInfo(accountInfo);
                    listViewItem.SubItems[2].Text = accountInfo.Password;
                }
            }
        }

        private void 好友管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count > 0)
            {
                ListViewItem listViewItem = this.listView1.SelectedItems[0];
                AccountInfo accountInfo = (AccountInfo)listViewItem.Tag;
                if (accountInfo.ActiveStatus == ActiveStatus.AlreadyActive)
                {
                    FriendsManage friendsManage = new FriendsManage(this, accountInfo);
                    friendsManage.ShowDialog();
                }
                else
                    MessageBox.Show("选择账户尚未验证激活状态！");
            }
        }

        private void button17_Click(object sender, EventArgs e)
        {
            IList<AccountInfo> accounts = new List<AccountInfo>();

            for (int i = 0; i < this.listView1.Items.Count; i++)
            {
                AccountInfo accountInfo = (AccountInfo)this.listView1.Items[i].Tag;
                if (this.listView1.Items[i].Checked && accountInfo.ActiveStatus == ActiveStatus.AlreadyActive)
                {
                    accounts.Add(accountInfo);
                }
            }
            if (accounts.Count == 0)
            {
                MessageBox.Show("尚未选择项或选择的账户尚未进行激活状态验证！");
                return;
            }

            SetControlDisabled();

            Thread t = new Thread(new ParameterizedThreadStart(InstallParkApp));
            t.Start(accounts);
            lstThread.Add(t);
        }

        //为选定账户批量添加挣车位组件
        void InstallParkApp(object obj)
        {
            this.Invoke(new DAppendText(AppendText),
                string.Format("[{0}]：开始批量添加挣车位组件……\n",
                    DateTime.Now.ToString("HH:mm:ss")));

            IList<AccountInfo> accountInfos = (List<AccountInfo>)obj;

            for (int i = 0; i < accountInfos.Count; i++)
            {
                AccountInfo accountInfo = accountInfos[i];
                User user = new User();
                this.Invoke(new DAppendText(AppendText),
                    string.Format("[{0}]：[{1}]开始登录系统……",
                        DateTime.Now.ToString("HH:mm:ss"),
                        string.Format("{0}", accountInfo.Email)));
                if (user.Login(accountInfo))
                {
                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：[{1}]成功登录系统！",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name)));
                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：[{1}]开始添加挣车位组件！",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name)));
                    user.InstallParkApp();
                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：[{1}]添加挣车位组件完成！",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name)));
                    user.Logout();
                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：[{1}]退出系统！\n",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name)));
                }
                if (i + 1 < accountInfos.Count)
                    Thread.Sleep(delayConnect * 1000);

            }
            this.Invoke(new DAppendText(AppendText),
                string.Format("[{0}]：批量添加挣车位组件完成！\n",
                    DateTime.Now.ToString("HH:mm:ss")));

            this.Invoke(new DRestoreControlEnabled(RestoreControlEnabled));
        }

        //为选定账户批量添加选定组件
        void InstallApp(object obj)
        {
            this.Invoke(new DAppendText(AppendText),
                string.Format("[{0}]：开始批量添加组件……\n",
                    DateTime.Now.ToString("HH:mm:ss")));

            IList<AccountInfo> accountInfos = (List<AccountInfo>)obj;

            for (int i = 0; i < accountInfos.Count; i++)
            {
                AccountInfo accountInfo = accountInfos[i];
                User user = new User();
                this.Invoke(new DAppendText(AppendText),
                    string.Format("[{0}]：[{1}]开始登录系统……",
                        DateTime.Now.ToString("HH:mm:ss"),
                        string.Format("{0}", accountInfo.Email)));
                if (user.Login(accountInfo))
                {
                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：[{1}]成功登录系统！\n",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name)));

                    for (int j = 0; j < addAppInfos.Count; j++)
                    {
                        this.Invoke(new DAppendText(AppendText),
                            string.Format("[{0}]：[{1}]开始添加{2}组件……",
                                DateTime.Now.ToString("HH:mm:ss"),
                                string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name),
                                addAppInfos[j].Name));

                        user.InstallApp(addAppInfos[j].Id);

                        this.Invoke(new DAppendText(AppendText),
                            string.Format("[{0}]：[{1}]添加{2}组件完成！ 进度：{3}\n",
                                DateTime.Now.ToString("HH:mm:ss"),
                                string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name),
                                addAppInfos[j].Name,
                                string.Format("{0}/{1}(帐号) {2}/{3}(组件)", (i + 1).ToString(), accountInfos.Count.ToString(), (j + 1).ToString(), addAppInfos.Count.ToString())));
                        if (i + 1 < addAppInfos.Count)
                            Thread.Sleep(delayConnect * 1000);
                    }
                    user.Logout();
                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：[{1}]退出系统！\n",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name)));
                }
                //if (i + 1 < accountInfos.Count)
                //    Thread.Sleep(delayConnect * 1000);

            }
            this.Invoke(new DAppendText(AppendText),
                string.Format("[{0}]：批量添加挣车位组件完成！\n",
                    DateTime.Now.ToString("HH:mm:ss")));

            this.Invoke(new DRestoreControlEnabled(RestoreControlEnabled));
        }

        private void button18_Click(object sender, EventArgs e)
        {
            IList<AccountInfo> masterAccountInfos = new List<AccountInfo>();

            foreach (DictionaryEntry de in htAccountInfo)
            {
                AccountInfo accountInfo = (AccountInfo)de.Value;
                if (accountInfo.ActiveStatus == ActiveStatus.AlreadyActive && accountInfo.IsMaster)
                    masterAccountInfos.Add(accountInfo);
            }

            if (masterAccountInfos.Count > 0)
            {
                this.SetControlDisabled();
                Thread t = new Thread(new ParameterizedThreadStart(StatisticsParkMoney));
                t.Start(masterAccountInfos);
                lstThread.Add(t);
            }
            else
            {
                MessageBox.Show("尚未设定主号或所设定主号未激活！");
            }
        }

        //统计选定账户挣车位金钱
        public void StatisticsParkMoney(object obj)
        {
            this.Invoke(new DAppendText(AppendText),
                string.Format("[{0}]：开始统计挣车位金钱……\n",
                    DateTime.Now.ToString("HH:mm:ss")));

            IList<AccountInfo> accountInfos = (List<AccountInfo>)obj;

            User user = new User();
            string verify = string.Empty;
            StringBuilder sbStatisticsParkMoney = new StringBuilder();
            sbStatisticsParkMoney.AppendLine("uid\t姓名\t车数\t当前停车收入\t车资\t现金\t总资产");
            for (int i = 0; i < accountInfos.Count; i++)
            {
                AccountInfo masterAccountInfo = accountInfos[i];
                if (verify == string.Empty)
                {
                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：[{1}]开始登录系统……",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0}", masterAccountInfo.Email)));

                    if (user.Login(masterAccountInfo))
                    {
                        this.Invoke(new DAppendText(AppendText),
                          string.Format("[{0}]：[{1}]成功登录系统！",
                              DateTime.Now.ToString("HH:mm:ss"),
                                string.Format("{0},{1}", masterAccountInfo.UserInfo.uid, masterAccountInfo.UserInfo.real_name)));
                        
                        verify = user.GetVerify();

                        this.Invoke(new DAppendText(AppendText),
                          string.Format("[{0}]：获取VerifyCode：{1}",
                              DateTime.Now.ToString("HH:mm:ss"),
                                string.Format("{0}", verify)));

                        user.Logout();

                        this.Invoke(new DAppendText(AppendText),
                            string.Format("[{0}]：[{1}]退出系统！\n",
                                DateTime.Now.ToString("HH:mm:ss"),
                                string.Format("{0},{1}", masterAccountInfo.UserInfo.uid, masterAccountInfo.UserInfo.real_name)));

                        this.Invoke(new DAppendText(AppendText),
                            string.Format("[{0}]：依次获取各账户挣车位金钱：",
                                DateTime.Now.ToString("HH:mm:ss"),
                                string.Format("{0},{1}", masterAccountInfo.UserInfo.uid, masterAccountInfo.UserInfo.real_name)));
                    }
                }
                ParkInfo parkInfo = Park.GetParkInfoByUid(verify, masterAccountInfo.UserInfo.uid);
                this.Invoke(new DAppendText(AppendText),
                    string.Format("[{0}]：({1})[{2}：{3}]：车({4})：{5} 现金：{6} 总资产：{7}",
                        DateTime.Now.ToString("HH:mm:ss"),
                        string.Format("{0}/{1}",(i+1).ToString(),accountInfos.Count.ToString()),
                        masterAccountInfo.AccountGroupInfo == null ? "未分组" : masterAccountInfo.AccountGroupInfo.Name,
                        string.Format("{0},{1}", masterAccountInfo.UserInfo.uid, masterAccountInfo.UserInfo.real_name),
                        parkInfo.CarInfos.Count.ToString(), parkInfo.ParkAmountInfo.AllCarAmount.ToString(),
                        parkInfo.ParkAmountInfo.Cash.ToString(),parkInfo.ParkAmountInfo.TotalAmount.ToString()));

                sbStatisticsParkMoney.AppendLine(string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}",
                    masterAccountInfo.UserInfo.uid,
                    masterAccountInfo.UserInfo.real_name,
                    parkInfo.CarInfos.Count.ToString(),
                    parkInfo.CarInfos.Sum(c => c.park_profit).ToString(),
                    parkInfo.ParkAmountInfo.AllCarAmount.ToString(),
                    parkInfo.ParkAmountInfo.Cash.ToString(),
                    parkInfo.ParkAmountInfo.TotalAmount.ToString()));

                if (i + 1 < accountInfos.Count)
                    Thread.Sleep(delayConnect * 1000);
            }
            string statisticsParkMoneyfile = Path.Combine(Application.StartupPath, "车资统计.xlt");

            using (StreamWriter sw = new StreamWriter(statisticsParkMoneyfile, false, Encoding.Default))
            {
                sw.WriteLine(sbStatisticsParkMoney.ToString());
            }
            this.Invoke(new DAppendText(AppendText),
                string.Format("[{0}]：统计挣车位金钱完成，并生成车资统计报表：{1}！",
                    DateTime.Now.ToString("HH:mm:ss"),
                    statisticsParkMoneyfile));

            this.Invoke(new DRestoreControlEnabled(RestoreControlEnabled));
        }

        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count > 0)
            {
                if (MessageBox.Show("确定删除该帐户吗？", "请确定", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    ListViewItem listViewItem = this.listView1.SelectedItems[0];
                    AccountInfo accountInfo = (AccountInfo)listViewItem.Tag;
                    Account.Delete(accountInfo);
                    htAccountInfo[accountInfo.Email] = null;

                    //if (accountInfo.IsMaster)
                    //    DeleteAccountFromAccountGroup(SystemGroup.主号组.ToString(), accountInfo);

                    //DeleteAccountFromAccountGroup(this.ddlGroup.Text,accountInfo);

                    //if (accountInfo.AccountGroupInfo != null)
                    //{
                    //    if(this.ddlGroup.Text != accountInfo.AccountGroupInfo.Name)
                    //        DeleteAccountFromAccountGroup(accountInfo.AccountGroupInfo.Name, accountInfo);
                    //}
                    //else
                    //    DeleteAccountFromAccountGroup(SystemGroup.未分组.ToString(), accountInfo);

                    //DeleteAccountFromAccountGroup(AccountGroup.GetSystemGroupName(accountInfo.ActiveStatus), accountInfo);

                    //if (this.ddlGroup.Text != SystemGroup.全部.ToString())
                    //{
                    //    DeleteAccountFromAccountGroup(SystemGroup.全部.ToString(), accountInfo);
                    //}

                    //htAccountInfo.Remove(accountInfo.Email);

                    //if (accountInfo.UserInfo != null)
                    //    htAccountInfoByUid.Remove(accountInfo.UserInfo.uid);
                    this.ddlGroup_SelectedIndexChanged(this.ddlGroup, EventArgs.Empty);
                    MessageBox.Show("删除完成！");
                }
            }
        }

        public void AddAccountToAccountGroup(string groupName, AccountInfo accountInfo,bool checkAccountInfoExist)
        {
            if (htAccountGroupInfo[groupName] == null)
            {
                AccountGroupInfo accountGroupInfo = new AccountGroupInfo
                {
                    Id = Guid.NewGuid(),
                    Name = groupName
                };
                accountGroupInfo.AccountInfos.Add(accountInfo);
                htAccountGroupInfo[groupName] = accountGroupInfo;
            }
            else
            {
                AccountGroupInfo accountGroupInfo = (AccountGroupInfo)htAccountGroupInfo[groupName] ;
                if(checkAccountInfoExist)
                {
                    if(accountGroupInfo.AccountInfos.Where(a => a.Email == accountInfo.Email).Count() == 0)
                        accountGroupInfo.AccountInfos.Add(accountInfo);
                }
                else
                    accountGroupInfo.AccountInfos.Add(accountInfo);

                htAccountGroupInfo[groupName] = accountGroupInfo;
            }
        }

        IList<AccountInfo> GetHtAccountInfos(string groupName)
        {
            IList<AccountInfo> accountInfos = new List<AccountInfo>();

            if (htAccountGroupInfo[groupName] != null)
            {
                AccountGroupInfo accountGroupInfo = (AccountGroupInfo)htAccountGroupInfo[groupName];
                accountInfos = accountGroupInfo.AccountInfos;
            }

            return accountInfos;
        }

        void DeleteAccountFromAccountGroup(string groupName, AccountInfo accountInfo)
        {
            if (htAccountGroupInfo[groupName] != null)
            {
                AccountGroupInfo accountGroupInfo = (AccountGroupInfo)htAccountGroupInfo[groupName];
                accountGroupInfo.AccountInfos.Remove(accountInfo);
                htAccountGroupInfo[groupName] = accountGroupInfo;
            }
        }

        private void button19_Click(object sender, EventArgs e)
        {
            IList<AccountInfo> ccountInfos = GetHtAccountInfos(this.ddlGroup.Text);

            if (ccountInfos.Count > 0)
            {
                SetControlDisabled();

                Thread t = new Thread(new ParameterizedThreadStart(StatisticsParkMoney));
                t.Start(ccountInfos);
                lstThread.Add(t);
            }
            else
            {
                MessageBox.Show("尚未选定项！");
            }
        }

        private void 我的车ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count > 0)
            {
                ListViewItem listViewItem = this.listView1.SelectedItems[0];
                AccountInfo accountInfo = (AccountInfo)listViewItem.Tag;
                if (accountInfo.ActiveStatus == ActiveStatus.AlreadyActive || accountInfo.ActiveStatus == ActiveStatus.AppForbided)
                {
                    MyCar myCar = new MyCar(this, accountInfo);
                    myCar.ShowDialog();
                }
                else
                    MessageBox.Show("尚未选择项或者选择账户处于未验证激活或者组件被封状态！");
            }
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < this.listView1.Items.Count; i++)
            {
                this.listView1.Items[i].Checked = this.checkBox1.Checked;
            }
        }

        private void 拉力赛ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count > 0)
            {
                ListViewItem listViewItem = this.listView1.SelectedItems[0];
                AccountInfo accountInfo = (AccountInfo)listViewItem.Tag;
                if (accountInfo.ActiveStatus == ActiveStatus.AlreadyActive)
                {
                    this.Invoke(new DAppendText(AppendText), (string.Format("[{0}]：[{1}]开始登录系统……",
                       DateTime.Now.ToString("HH:mm:ss"),
                       string.Format("{0}", accountInfo.Email))));

                    User user = new User();
                    if (user.Login(accountInfo))
                    {
                        accountInfo.FriendInfos = user.GetAllUserInfos();
                        Account.StaticFriends(accountInfo);

                        this.Invoke(new DAppendText(AppendText),
                            string.Format("[{0}]：[{1}]登录系统成功，并重新获取好友列表，缓存到本地！\n",
                                DateTime.Now.ToString("HH:mm:ss"),
                                string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name)));

                        user.Logout();

                        this.Invoke(new DAppendText(AppendText),
                            string.Format("[{0}]：[{1}]退出系统！\n",
                                DateTime.Now.ToString("HH:mm:ss"),
                                string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name)));

                    }

                    MyTeam myTeam = new MyTeam(this, accountInfo);
                    myTeam.ShowDialog();
                }
                else
                    MessageBox.Show("尚未选择项或者选择账户处于未验证激活或者组件被封状态！");
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            IList<AccountInfo> accountInfos = new List<AccountInfo>();
            for (int i = 0; i < this.listView1.Items.Count; i++)
            {
                if (this.listView1.Items[i].Checked)
                {
                    ListViewItem listViewItem = this.listView1.Items[i];
                    AccountInfo account = (AccountInfo)listViewItem.Tag;
                    if (account.ActiveStatus == ActiveStatus.AlreadyActive || account.ActiveStatus == ActiveStatus.AppForbided)
                        accountInfos.Add(account);
                }
            }
            if (accountInfos.Count > 1)
            {
                this.SetControlDisabled();

                Thread t = new Thread(new ParameterizedThreadStart(AddFriendsWithSelectedAccounts));
                t.Start(accountInfos);
                lstThread.Add(t);
            }
            else
            {
                MessageBox.Show("选择账户数应多于一个并且选择账户应以验证激活状态！");
            }
        }

        private void 用他的邀请码提交注册ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.listView1.SelectedItems.Count > 0)
                {
                    ListViewItem listViewItem = this.listView1.SelectedItems[0];
                    AccountInfo accountInfo = (AccountInfo)listViewItem.Tag;
                    if (accountInfo.ActiveStatus == ActiveStatus.AlreadyActive)
                    {
                        Form1 form1 = new Form1(this, accountInfo);
                        form1.ShowDialog();
                    }
                    else
                        MessageBox.Show("选择账户尚未验证激活状态！");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error：" + ex.Message);
            }

        }

        private void button20_Click(object sender, EventArgs e)
        {
            addAppInfos.Clear();
            IList<AccountInfo> accountInfos = new List<AccountInfo>();
            for (int i = 0; i < this.listView1.Items.Count; i++)
            {
                if (this.listView1.Items[i].Checked)
                {
                    ListViewItem listViewItem = this.listView1.Items[i];
                    AccountInfo account = (AccountInfo)listViewItem.Tag;
                    if (account.ActiveStatus == ActiveStatus.AlreadyActive || account.ActiveStatus == ActiveStatus.AppForbided)
                        accountInfos.Add(account);
                }
            }
            if (accountInfos.Count > 0)
            {
                AddApp addApp = new AddApp(this,accountInfos[0]);
                if (addApp.ShowDialog() == DialogResult.OK)
                {
                    if (addApp.addAppInfos.Count != 0)
                    {
                        addAppInfos = addApp.addAppInfos;

                        SetControlDisabled();
                        Thread t = new Thread(new ParameterizedThreadStart(InstallApp));
                        t.Start(accountInfos);
                        lstThread.Add(t);
                    }
                    else
                        MessageBox.Show("尚未选择组件！");
                }
            }
            else
            {
                MessageBox.Show("尚未选定项或者选择账户数没有验证激活状态！");
            }

        }

        private void button21_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定要中断当前执行进程吗？", "请确定", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                new Thread(new ThreadStart(Stop)).Start();
            }
        }

        private void button22_Click(object sender, EventArgs e)
        {
            IList<AccountInfo> accountInfos = new List<AccountInfo>();
            for (int i = 0; i < this.listView1.Items.Count; i++)
            {
                if (this.listView1.Items[i].Checked)
                {
                    ListViewItem listViewItem = this.listView1.Items[i];
                    AccountInfo account = (AccountInfo)listViewItem.Tag;
                    if (account.ActiveStatus == ActiveStatus.AlreadyActive || account.ActiveStatus == ActiveStatus.AppForbided)
                        accountInfos.Add(account);
                }
            }
            if (accountInfos.Count > 1)
            {
                this.SetControlDisabled();

                Thread t = new Thread(new ParameterizedThreadStart(AddFriendsWithAToBAndBToC));
                t.Start(accountInfos);
                lstThread.Add(t);
            }
            else
            {
                MessageBox.Show("选择账户数应多于一个并且选择账户应以验证激活状态！");
            }
        }

        public void ProcessLoginKaiXin001(AccountInfo accountInfo)
        {
            if (accountInfo.ActiveStatus == ActiveStatus.AlreadyActive)
            {
                User user = new User();
                if (user.Login(accountInfo))
                {
                    //获取旧的   
                    StringBuilder cookie = new StringBuilder(new String(' ', 2048));
                    int datasize = cookie.Length;
                    bool b = InternetGetCookie("http://www.kaixin001.com", null, cookie, ref datasize);
                    //删除旧的   
                    foreach (string fileName in System.IO.Directory.GetFiles(System.Environment.GetFolderPath(Environment.SpecialFolder.Cookies)))
                    {
                        if (fileName.ToLower().IndexOf("kaixin001") > 0)
                        {
                            System.IO.File.Delete("kaixin001");
                        }
                    }
                    //生成新的   
                    string cookieexpires = string.Format(";expires={0}", DateTime.Now.AddSeconds(30).ToString("r"));//";expires=Sun,22-Feb-2099 00:00:00 GMT";
                    b = InternetSetCookie("http://kaixin001.com", "_uid", accountInfo.UserInfo.uid + cookieexpires);
                    b = InternetSetCookie("http://kaixin001.com", "_email", accountInfo.Email.Replace("@", "%40") + cookieexpires);
                    b = InternetSetCookie("http://kaixin001.com", "_user", user.UserInfo.AuthenticationCookieCollection[0].Value + cookieexpires);
                    Process.Start("iexplore.exe", "http://www.kaixin001.com/home");
                }
                else
                    MessageBox.Show("账号密码错误！");
            }
            else
                MessageBox.Show("选择账户尚未验证激活状态！");
        }

        private void 打开浏览器登录ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count > 0)
            {
                ListViewItem listViewItem = this.listView1.SelectedItems[0];
                AccountInfo accountInfo = (AccountInfo)listViewItem.Tag;
                ProcessLoginKaiXin001(accountInfo);
            }
        }

        private void button23_Click(object sender, EventArgs e)
        {
            IList<AccountInfo> accountInfos = new List<AccountInfo>();
            for (int i = 0; i < this.listView1.Items.Count; i++)
            {
                if (this.listView1.Items[i].Checked)
                {
                    ListViewItem listViewItem = this.listView1.Items[i];
                    AccountInfo account = (AccountInfo)listViewItem.Tag;
                    if (account.ActiveStatus == ActiveStatus.AlreadyActive || account.ActiveStatus == ActiveStatus.AppForbided)
                        accountInfos.Add(account);
                }
            }
            if (accountInfos.Count > 0)
            {
                string accountfile = Path.Combine(Application.StartupPath, "accounts.xlt");
                using (StreamWriter sw = new StreamWriter(Path.Combine(Application.StartupPath, "accounts.xlt"), false, Encoding.Default))
                {
                    sw.WriteLine(string.Format("{0}\t{1}\t{2}\t{3}", "uid", "email", "password", "real_name"));
                    for (int i = 0; i < accountInfos.Count; i++)
                    {
                        AccountInfo accountInfo = accountInfos[i];
                        sw.WriteLine(string.Format("{0}\t{1}\t{2}\t{3}", accountInfo.UserInfo.uid, accountInfo.Email, accountInfo.Password, accountInfo.UserInfo.real_name));
                    }

                    string message = string.Format("导出帐号完成，文件生成到：{0}", accountfile);

                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：{1}",
                            DateTime.Now.ToString("HH:mm:ss"),
                            message));

                    MessageBox.Show(message);
                }
            }
            else
            {
                MessageBox.Show("尚未选择项或者选择账户未验证激活状态！");
            }
        }

        private void button24_Click(object sender, EventArgs e)
        {
            IList<AccountInfo> accountInfos = new List<AccountInfo>();
            for (int i = 0; i < this.listView1.Items.Count; i++)
            {
                if (this.listView1.Items[i].Checked)
                {
                    ListViewItem listViewItem = this.listView1.Items[i];
                    AccountInfo account = (AccountInfo)listViewItem.Tag;
                    accountInfos.Add(account);
                }
            }
            if (accountInfos.Count > 0)
            {
                if (MessageBox.Show(string.Format("确定删除选择的{0}个账户吗？", accountInfos.Count.ToString()), "请确定", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    for (int i = 0; i < accountInfos.Count; i++)
                    {
                        AccountInfo accountInfo = accountInfos[i];
                        htAccountInfo[accountInfo.Email] = null;
                    }
                    Account.Delete(accountInfos);
                    this.ddlGroup_SelectedIndexChanged(this.ddlGroup, EventArgs.Empty);
                    MessageBox.Show("删除完成！");

                }
            }
            else
            {
                MessageBox.Show("尚未选定项！");
            }
        }

        private void button25_Click(object sender, EventArgs e)
        {
            string email = Interaction.InputBox("请输入email", "email输入", string.Empty, 100, 0);
            if (!string.IsNullOrEmpty(email) && htAccountInfo[email] == null)
            {
                string password = Interaction.InputBox("请输入密码", "密码输入", string.Empty, 100, 0);
                if (!string.IsNullOrEmpty(password))
                {
                    AccountInfo accountInfo = new AccountInfo 
                    {
                        Email = email,
                        Password = password,
                        ActiveStatus = ActiveStatus.NoVerifyActive
                    };
                    Account.Add(accountInfo);
                    htAccountInfo[email] = accountInfo;
                    AddAccountToAccountGroup(SystemGroup.全部.ToString(), accountInfo, false);
                    AddAccountToAccountGroup(SystemGroup.未分组.ToString(), accountInfo, false);
                    AddAccountToAccountGroup(SystemGroup.未验证组.ToString(), accountInfo, false);

                    ListViewItem item = new ListViewItem(
                        new string[] { 
                                (this.listView1.Items.Count + 1).ToString(),
                                accountInfo.Email, 
                                accountInfo.Password, 
                                accountInfo.UserInfo == null ? string.Empty : accountInfo.UserInfo.uid, 
                                accountInfo.UserInfo == null ? string.Empty : accountInfo.UserInfo.real_name, 
                                Account.GetAccountActiveStatusDesctiption(accountInfo.ActiveStatus),
                                accountInfo.AccountGroupInfo == null ? string.Empty : accountInfo.AccountGroupInfo.Name,
                                accountInfo.IsMaster ? "是" : "否"
                            }
                    );
                    item.Tag = accountInfo;
                    accountInfo.Tag = item;

                    this.listView1.Items.Add(item);
                    MessageBox.Show("添加帐号完成！");
                }
                else
                    MessageBox.Show("password输入为空！");
            }
            else
            {
                MessageBox.Show("Email输入为空或已添加！");
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void 验证好友添加请求ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count > 0)
            {
                ListViewItem listViewItem = this.listView1.SelectedItems[0];
                AccountInfo accountInfo = (AccountInfo)listViewItem.Tag;
            }
        }

        private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start("iexplore.exe", "http://www.novelindex.cn/kaixintools/");
        }

        private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start("iexplore.exe", "http://www.novelindex.cn/");
        }

        private void button27_Click(object sender, EventArgs e)
        {
            IList<AccountInfo> accountInfos = new List<AccountInfo>();
            for (int i = 0; i < this.listView1.Items.Count; i++)
            {
                if (this.listView1.Items[i].Checked)
                {
                    ListViewItem listViewItem = this.listView1.Items[i];
                    AccountInfo account = (AccountInfo)listViewItem.Tag;
                    if (account.ActiveStatus == ActiveStatus.AlreadyActive)
                        accountInfos.Add(account);
                }
            }
            if (accountInfos.Count > 0)
            {
                Thread t = new Thread(new ParameterizedThreadStart(Oil));
                t.Start(accountInfos);
                lstThread.Add(t);
            }
            else
            {
                MessageBox.Show("尚未选择项或者选择账户处于未验证激活或者组件被封状态！");
            }
        }

        void Oil(object obj)
        {
            this.Invoke(new DSetControlDisabled(SetControlDisabled));

            this.Invoke(new DAppendText(AppendText), (string.Format("[{0}]：拉力赛加油：\n",DateTime.Now.ToString("HH:mm:ss"))));

            IList<AccountInfo> accountInfos = (List<AccountInfo>)obj;
            for (int i = 0; i < accountInfos.Count; i++)
            {
                AccountInfo accountInfo = accountInfos[i];
                User user = new User();

                this.Invoke(new DAppendText(AppendText), (string.Format("[{0}]：[{1}]开始登录系统……",
                   DateTime.Now.ToString("HH:mm:ss"),
                   string.Format("{0}", accountInfo.Email))));

                if (user.Login(accountInfo))
                {
                    accountInfo.FriendInfos = user.GetAllUserInfos();
                    Account.StaticFriends(accountInfo);

                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：[{1}]登录系统成功，并重新获取好友列表，缓存到本地！\n",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name)));

                    Hashtable htFriend = new Hashtable();

                    for (int j = 0; j < accountInfo.FriendInfos.Count; j++)
                    {
                        SimpleUserInfo simpleUserInfo = accountInfo.FriendInfos[j];
                        htFriend[simpleUserInfo.uid] = simpleUserInfo;
                    }

                    string verify = string.Empty;

                    this.Invoke(new DAppendText(AppendText), (string.Format("[{0}]：[{1}]获取拉力赛信息：",
                        DateTime.Now.ToString("HH:mm:ss"),
                        string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name))));

                    try
                    {
                        MyTeamInfo myTeamInfo = user.GetMyTeamInfo(ref verify);

                        this.Invoke(new DAppendText(AppendText), (string.Format("[{0}]：[{1}]获取拉力赛信息完成！\n",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name))));

                        //IList<TeamInfo> teamInfos = myTeamInfo.TeamInfos.Where(t => t.canoil).ToList();

                        IList<TeamInfo> teamInfos = myTeamInfo.TeamInfos;
                        if (teamInfos.Count > 0)
                        {
                            for (int j = 0; j < teamInfos.Count; j++)
                            {
                                TeamInfo teamInfo = teamInfos[j];

                                IList<OilInfo> oilInfos = user.GetUserTeamOilInfos(teamInfo.matchuid, teamInfo.matchid);

                                for (int k = 0; k < oilInfos.Count; k++)
                                {
                                    OilInfo oilInfo = oilInfos[k];
                                    teamInfo.CarTeamInfos[k].OilInfo = oilInfo;
                                }

                                bool is_friend = false;
                                for (int k = 0; k < teamInfo.CarTeamInfos.Count; k++)
                                {
                                    is_friend = false;
                                    CarTeamInfo carTeamInfo = teamInfo.CarTeamInfos[k];
                                    OilInfo oilInfo = teamInfo.CarTeamInfos[k].OilInfo;

                                    for (int m = 0; m < carTeamInfo.SimpleUserInfos.Count; m++)
                                    {
                                        if (htFriend[carTeamInfo.SimpleUserInfos[m].uid] != null)
                                        {
                                            is_friend = true;
                                            break;
                                        }
                                    }
                                    if (is_friend && oilInfo != null)
                                    {
                                        try
                                        {
                                            this.Invoke(new DAppendText(AppendText), (string.Format("[{0}]：[{1}]{2}",
                                                DateTime.Now.ToString("HH:mm:ss"),
                                                string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name),
                                                Team.Oil(verify, oilInfo.teamuid, oilInfo.teamid, OilType.加油))));
                                        }
                                        catch (Exception ex)
                                        {
                                            this.Invoke(new DAppendText(AppendText), (string.Format("[{0}]：[{1}]执行异常：{2}",
                                                DateTime.Now.ToString("HH:mm:ss"),
                                                string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name),
                                                ex.Message)));
                                        }
                                        if (k + 1 < oilInfos.Count)
                                            Thread.Sleep(delayConnect * 1000);
                                    }
                                    else
                                    {
                                        //this.Invoke(new DAppendText(AppendText), (string.Format("[{0}]：[{1}]{2}\n",
                                        //    DateTime.Now.ToString("HH:mm:ss"),
                                        //    string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name),
                                        //    string.Format("{0}不是你的好友，不能给该车队加油或捣鬼。", string.Join("-", GetArray<string>.Get(carTeamInfo.SimpleUserInfos.Select(u => u.real_name).ToList()))))));
                                    }
                                }
                                if (is_friend && j + 1 < teamInfos.Count)
                                    Thread.Sleep(delayConnect * 1000);
                            }
                        }
                        else
                        {
                            this.Invoke(new DAppendText(AppendText), (string.Format("[{0}]：[{1}]：{2}\n",
                                DateTime.Now.ToString("HH:mm:ss"),
                                string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name),
                                string.Format("没有好友参加拉力赛，或好友拉力赛油已加满！"))));
                        }
                    }
                    catch (Exception ex)
                    {
                        this.Invoke(new DAppendText(AppendText), (string.Format("[{0}]：[{1}]执行异常：{2}",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name),
                            ex.Message)));
                    }

                }

                user.Logout();

                this.Invoke(new DAppendText(AppendText), (string.Format("[{0}]：[{1}]成功退出系统！\n",
                    DateTime.Now.ToString("HH:mm:ss"),
                    string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name))));

            }

            this.Invoke(new DAppendText(AppendText), (string.Format("[{0}]：批量加油完成！\n",DateTime.Now.ToString("HH:mm:ss"))));

            this.Invoke(new DSetControlDisabled(RestoreControlEnabled));
        }

        void TeamBegin(object obj)
        {
            this.Invoke(new DSetControlDisabled(SetControlDisabled));

            this.Invoke(new DAppendText(AppendText), (string.Format("[{0}]：批量启动拉力赛：\n", DateTime.Now.ToString("HH:mm:ss"))));

            IList<AccountInfo> accountInfos = (List<AccountInfo>)obj;
            for (int i = 0; i < accountInfos.Count; i++)
            {
                AccountInfo accountInfo = accountInfos[i];
                User user = new User();

                this.Invoke(new DAppendText(AppendText), (string.Format("[{0}]：[{1}]开始登录系统……",
                   DateTime.Now.ToString("HH:mm:ss"),
                   string.Format("{0}", accountInfo.Email))));

                if (user.Login(accountInfo))
                {
                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：[{1}]登录系统成功！\n",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name)));

                    string verify = string.Empty;

                    this.Invoke(new DAppendText(AppendText), (string.Format("[{0}]：[{1}]获取拉力赛信息：",
                        DateTime.Now.ToString("HH:mm:ss"),
                        string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name))));

                    MyTeamInfo myTeamInfo = user.GetMyTeamInfo(ref verify);

                    this.Invoke(new DAppendText(AppendText), (string.Format("[{0}]：[{1}]获取拉力赛信息完成！\n",
                        DateTime.Now.ToString("HH:mm:ss"),
                        string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name))));

                    if (myTeamInfo.MyCarTeamInfo != null)
                    {
                        bool team_already_begin_flag;

                        this.Invoke(new DAppendText(AppendText), (string.Format("[{0}]：[{1}]启动车队：",
                           DateTime.Now.ToString("HH:mm:ss"),
                           string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name))));

                        OilInfo oilInfo = user.GetTeamBeginOilInfo(myTeamInfo.MyCarTeamInfo.matchuid, myTeamInfo.MyCarTeamInfo.matchid, out team_already_begin_flag);
                        if (!team_already_begin_flag)
                        {
                            if (oilInfo != null)
                            {
                                string message = Team.teambegin(verify, oilInfo.teamuid, oilInfo.teamid);
                                message = message ?? "你的车队已成功启动！";
                                Console.WriteLine(message);
                                this.Invoke(new DAppendText(AppendText), (string.Format("[{0}]：[{1}]{2}",
                                    DateTime.Now.ToString("HH:mm:ss"),
                                    string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name),
                                    message)));
                            }
                        }
                        else
                        {
                            this.Invoke(new DAppendText(AppendText), (string.Format("[{0}]：[{1}]你的车队今天已经启动！",
                               DateTime.Now.ToString("HH:mm:ss"),
                               string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name))));
                        }

                        this.Invoke(new DAppendText(AppendText), (string.Format("[{0}]：[{1}]完成启动车队！\n",
                           DateTime.Now.ToString("HH:mm:ss"),
                           string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name))));
                    }
                    else
                    {
                        this.Invoke(new DAppendText(AppendText), (string.Format("[{0}]：[{1}]尚未组建车队！\n",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name))));
 
                    }

                    user.Logout();

                    this.Invoke(new DAppendText(AppendText), (string.Format("[{0}]：[{1}]成功退出系统！\n",
                        DateTime.Now.ToString("HH:mm:ss"),
                        string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name))));

                }
            }

            this.Invoke(new DAppendText(AppendText), (string.Format("[{0}]：批量启动拉力赛完成！\n", DateTime.Now.ToString("HH:mm:ss"))));

            this.Invoke(new DSetControlDisabled(RestoreControlEnabled));

        }

        private void button26_Click(object sender, EventArgs e)
        {
            IList<AccountInfo> accountInfos = new List<AccountInfo>();
            for (int i = 0; i < this.listView1.Items.Count; i++)
            {
                if (this.listView1.Items[i].Checked)
                {
                    ListViewItem listViewItem = this.listView1.Items[i];
                    AccountInfo account = (AccountInfo)listViewItem.Tag;
                    if (account.ActiveStatus == ActiveStatus.AlreadyActive)
                        accountInfos.Add(account);
                }
            }
            if (accountInfos.Count > 0)
            {
                Thread t = new Thread(new ParameterizedThreadStart(TeamBegin));
                t.Start(accountInfos);
                lstThread.Add(t);
            }
            else
            {
                MessageBox.Show("尚未选择项或者选择账户处于未验证激活或者组件被封状态！");
            }
        }

        void UploadPic(object obj)
        {
            this.Invoke(new DSetControlDisabled(SetControlDisabled));

            this.Invoke(new DAppendText(AppendText), (string.Format("[{0}]：批量上传照片：\n", DateTime.Now.ToString("HH:mm:ss"))));

            IList<AccountInfo> accountInfos = (List<AccountInfo>)obj;

            for (int i = 0; i < accountInfos.Count; i++)
            {
                AccountInfo accountInfo = accountInfos[i];

                User user = new User();

                this.Invoke(new DAppendText(AppendText), (string.Format("[{0}]：[{1}]开始登录系统……",
                   DateTime.Now.ToString("HH:mm:ss"),
                   string.Format("{0}", accountInfo.Email))));

                if (user.Login(accountInfo))
                {
                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：[{1}]登录系统成功！\n",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name)));

                    CookieContainer cookieContainer = new CookieContainer();

                    cookieContainer.Add(user.cc);

                    string picfilename = PicFileName[new Random().Next(0,PicFileName.Count)];

                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：[{1}]正在上传照片：{2}",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name),
                            picfilename));

                    string ss = Common.UploadFileEx(picfilename,
                        "http://www.kaixin001.com/set/upload_submit.php",
                        "icon",
                        "image/pjpeg",
                        new NameValueCollection(),
                        cookieContainer);

                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：[{1}]上传照片完成！\n",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name)));

                    user.Logout();

                    this.Invoke(new DAppendText(AppendText), (string.Format("[{0}]：[{1}]成功退出系统！\n",
                        DateTime.Now.ToString("HH:mm:ss"),
                        string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name))));
                }
            }

            this.Invoke(new DAppendText(AppendText), (string.Format("[{0}]：批量上传照片完成！\n", DateTime.Now.ToString("HH:mm:ss"))));

            this.Invoke(new DSetControlDisabled(RestoreControlEnabled));

        }

        IList<string> PicFileName = new List<string>();

        private void button28_Click(object sender, EventArgs e)
        {
            IList<AccountInfo> accountInfos = new List<AccountInfo>();
            for (int i = 0; i < this.listView1.Items.Count; i++)
            {
                if (this.listView1.Items[i].Checked)
                {
                    ListViewItem listViewItem = this.listView1.Items[i];
                    AccountInfo account = (AccountInfo)listViewItem.Tag;
                    if (account.ActiveStatus == ActiveStatus.AlreadyActive || account.ActiveStatus == ActiveStatus.AppForbided)
                        accountInfos.Add(account);
                }
            }
            if (accountInfos.Count > 0)
            {
                FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
                folderBrowserDialog1.Description = "请选择照片存放文件夹";
                folderBrowserDialog1.ShowNewFolderButton = false;
                DialogResult result = folderBrowserDialog1.ShowDialog();
                if (result == DialogResult.OK)
                {
                    string folderName = folderBrowserDialog1.SelectedPath;
                    if (folderName != "")
                    {
                        PicFileName = Common.GetPicFileNameFromFolder(folderName);
                        if (PicFileName.Count > 0)
                        {
                            Thread t = new Thread(new ParameterizedThreadStart(UploadPic));
                            t.Start(accountInfos);
                            lstThread.Add(t);
                        }
                        else
                        {
                            MessageBox.Show("选定的文件夹不存在图片！");
                        }
                    }
                }
                //Thread t = new Thread(new ParameterizedThreadStart(TeamBegin));
                //t.Start(accountInfos);
                //lstThread.Add(t);
                //User user = new User();
                //if (user.Login(accountInfos[0]))
                //{
                //    string cookie = string.Empty;
                //    for (int j = 0; j < user.cc.Count; j++)
                //    {
                //        cookie += string.Format("{0}={1};", user.cc[j].Name, user.cc[j].Value);
                //    }
                //    CookieContainer cookieContainer = new CookieContainer();
                //    cookieContainer.Add(user.cc);
                //    string ss = Common.UploadFileEx(@"E:\http_imgloadCAOA1QYD.jpg",
                //        "http://www.kaixin001.com/set/upload_submit.php",
                //        "icon",
                //        "image/pjpeg",
                //        new NameValueCollection(),
                //        cookieContainer);
                //}
            }
            else
            {
                MessageBox.Show("尚未选择项或者选择账户未验证激活状态！");
            }
        }

        private void button29_Click(object sender, EventArgs e)
        {
            if (this.saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                using(StreamWriter sw = new StreamWriter(this.saveFileDialog1.FileName,false,Encoding.Default))
                {
                    sw.WriteLine(this.richTextBox1.Text);
                }
                MessageBox.Show("ok！");
            }
        }

        private void button30_Click(object sender, EventArgs e)
        {
            IList<AccountInfo> accounts = new List<AccountInfo>();

            for (int i = 0; i < this.listView1.Items.Count; i++)
            {
                if (this.listView1.Items[i].Checked)
                {
                    ListViewItem listViewItem = this.listView1.Items[i];
                    listViewItem.SubItems[4].Text = "等待验证中……";
                    AccountInfo account = (AccountInfo)listViewItem.Tag;
                    accounts.Add(account);
                }
            }
            if (accounts.Count == 0)
            {
                MessageBox.Show("尚未选择项！");
                return;
            }

            this.SetControlDisabled();

            Thread t = new Thread(new ParameterizedThreadStart(VerifyAccountAppForbidedStatus));
            t.Start(accounts);
            lstThread.Add(t);
        }





        private void button129_Click(object sender, EventArgs e)
        {
//////////////////////////////////////////////////////////////
      /*      IList<AccountInfo> accountInfos = new List<AccountInfo>();

            bool existMaster = false;
            bool existChild = false;

            for (int i = 0; i < this.listView1.Items.Count; i++)
            {
                ListViewItem listViewItem = this.listView1.Items[i];
                AccountInfo account = (AccountInfo)listViewItem.Tag;
                if (account.ActiveStatus == ActiveStatus.AlreadyActive)
                {
                    if (account.IsMaster)
                        existMaster = true;
                    else
                        existChild = true;
                    accountInfos.Add(account);
                }
            }
            if (existChild && existMaster)
            {
                this.SetControlDisabled();

                Thread t = new Thread(new ParameterizedThreadStart(AddFriendsWithChildToMaster));
                t.Start(accountInfos);
                lstThread.Add(t);
            }
            else
            {
                MessageBox.Show(string.Format("分组“{0}”中主号或小号不存在！", this.ddlGroup.Text));
            }
 ///////////////////////////////////////////////////////
            IList<AccountInfo> accountInfos = new List<AccountInfo>();
            for (int i = 0; i < this.listView1.Items.Count; i++)
            {
                if (this.listView1.Items[i].Checked)
                {
                    ListViewItem listViewItem = this.listView1.Items[i];
                    AccountInfo account = (AccountInfo)listViewItem.Tag;
                    if (account.ActiveStatus == ActiveStatus.AlreadyActive)
                        accountInfos.Add(account);
                }
            }
            if (accountInfos.Count > 1)
            {
                this.SetControlDisabled();

                Thread t = new Thread(new ParameterizedThreadStart(AddFriendsWithSelectedAccounts));
                t.Start(accountInfos);
                lstThread.Add(t);
            }
            else
            {
                MessageBox.Show("选择账户数应多于一个并且选择账户应以验证激活状态！");
            }
      */  
 ///////////////////////////////////////////       
            int[,] arr = { { 0, 1, 8 }, { 2, 3, 9 }, { 4, 5, 10 }, { 6, 7, 11 }, { 8, 9, 12 }, { 10, 11, 13 }, { 12, 13, 14 } };
          //  this.Invoke(new DSetControlDisabled(SetControlDisabled));
            if (this.listView1.Items.Count < 15)
            {
                MessageBox.Show("本组账号的数量小于 15 的最小要求数量！");
            }
            else
            {

                for (int j = 0; j < 7; j++)//(arr.Length-1)
                {
                    IList<AccountInfo> accountInfos = new List<AccountInfo>();
                    //   accountInfos = new List<AccountInfo>();
                    for (int x = 0; x < 3; x++)
                    {
                        ListViewItem listViewItem = this.listView1.Items[arr[j, x]];
                        AccountInfo account = (AccountInfo)listViewItem.Tag;
                        if (account.ActiveStatus == ActiveStatus.AlreadyActive)
                            accountInfos.Add(account);
                    }

                    if (accountInfos.Count > 1)
                    {
                        this.SetControlDisabled();

                        Thread t = new Thread(new ParameterizedThreadStart(AddFriendsWithSelectedAccounts));
                        t.Start(accountInfos);
                        lstThread.Add(t);
                    }
                    else
                    {
                        MessageBox.Show("选择账户数应多于一个并且选择账户应以验证激活状态！");
                    }
                }
            }
            ///////////////////////////////////////////   
        }

        private void button130_Click(object sender, EventArgs e)
        {
            /////////对加好友//////////////////////////////////       
            int[,] arr = { { 0, 1, 8 }, { 2, 3, 9 }, { 4, 5, 10 }, { 6, 7, 11 }, { 8, 9, 12 }, { 10, 11, 13 }, { 12, 13, 14 } };
            //  this.Invoke(new DSetControlDisabled(SetControlDisabled));
            if (this.listView1.Items.Count < 15)
            {
                MessageBox.Show("本组账号的数量小于 15 的最小要求数量！");
            }
            else
            {

                for (int j = 0; j < 7; j++)//(arr.Length-1)
                {
                    IList<AccountInfo> accountInfos = new List<AccountInfo>();
                    //   accountInfos = new List<AccountInfo>();
                    for (int x = 0; x < 2; x++)
                    {
                        ListViewItem listViewItem = this.listView1.Items[arr[j, x]];
                        AccountInfo account = (AccountInfo)listViewItem.Tag;
                        if (account.ActiveStatus == ActiveStatus.AlreadyActive)
                            accountInfos.Add(account);
                    }

                    if (accountInfos.Count > 1)
                    {
                        this.SetControlDisabled();

                        Thread t = new Thread(new ParameterizedThreadStart(AddFriendsWithSelectedAccounts));
                        t.Start(accountInfos);
                        lstThread.Add(t);
                    }
                    else
                    {
                        MessageBox.Show("选择账户数应多于一个并且选择账户应以验证激活状态！");
                    }
                }
            }
            ///////////////////////////////////////////   
        }


        //为选定账户批量添加场景 by sym
        void CarUpScen(object obj)
        {
            this.Invoke(new DAppendText(AppendText),
                string.Format("[{0}]：开始批量添加场景……\n",
                    DateTime.Now.ToString("HH:mm:ss")));

            IList<AccountInfo> accountInfos = (List<AccountInfo>)obj;

            for (int i = 0; i < accountInfos.Count; i++)
            {
                AccountInfo accountInfo = accountInfos[i];
                User user = new User();
                string verify = string.Empty;
                this.Invoke(new DAppendText(AppendText),
                    string.Format("[{0}]：[{1}]开始登录系统……",
                        DateTime.Now.ToString("HH:mm:ss"),
                        string.Format("{0}", accountInfo.Email)));
                if (user.Login(accountInfo))
                {
                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：[{1}]成功登录系统！",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name)));
                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：[{1}]开始添加添加场景！",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name)));
                    verify = user.GetVerify();
                    user.InstallScen(verify, 18);
                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：[{1}]添加添加场景完成！",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name)));
                    user.Logout();
                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：[{1}]退出系统！\n",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name)));
                }
                if (i + 1 < accountInfos.Count)
                    Thread.Sleep(delayConnect * 1000);

            }
            this.Invoke(new DAppendText(AppendText),
                string.Format("[{0}]：批量添加添加场景完成！\n",
                    DateTime.Now.ToString("HH:mm:ss")));

            this.Invoke(new DRestoreControlEnabled(RestoreControlEnabled));
        }


        private void button131_Click_1(object sender, EventArgs e)
        {

////////////////////////////            
            {
                IList<AccountInfo> accounts = new List<AccountInfo>();

                for (int i = 0; i < this.listView1.Items.Count; i++)
                {
                    AccountInfo accountInfo = (AccountInfo)this.listView1.Items[i].Tag;
                    if (this.listView1.Items[i].Checked && accountInfo.ActiveStatus == ActiveStatus.AlreadyActive)
                    {
                        accounts.Add(accountInfo);
                    }
                }
                if (accounts.Count == 0)
                {
                    MessageBox.Show("尚未选择项或选择的账户尚未进行激活状态验证！");
                    return;
                }

                SetControlDisabled();

                Thread t = new Thread(new ParameterizedThreadStart(CarUpScen));
                t.Start(accounts);
                lstThread.Add(t);
            }            
            
 /////////////////////////////           
        }

        private void button31_Click(object sender, EventArgs e)
        {
            IList<AccountInfo> accountInfos = new List<AccountInfo>();
            for (int i = 0; i < this.listView1.Items.Count; i++)
            {
                if (this.listView1.Items[i].Checked)
                {
                    ListViewItem listViewItem = this.listView1.Items[i];
                    AccountInfo account = (AccountInfo)listViewItem.Tag;
                    if (account.ActiveStatus == ActiveStatus.AlreadyActive || account.ActiveStatus == ActiveStatus.AppForbided)
                        accountInfos.Add(account);
                }
            }
            if (accountInfos.Count > 1)
            {
                this.SetControlDisabled();

                Thread t = new Thread(new ParameterizedThreadStart(AddFriendsWith1To2And1To3));
                t.Start(accountInfos);
                lstThread.Add(t);
            }
            else
            {
                MessageBox.Show("选择账户数应多于一个并且选择账户应以验证激活状态！");
            }
        }

        private void button32_Click(object sender, EventArgs e)
        {
            IList<AccountInfo> accountInfos = new List<AccountInfo>();
            for (int i = 0; i < this.listView1.Items.Count; i++)
            {
                if (this.listView1.Items[i].Checked)
                {
                    ListViewItem listViewItem = this.listView1.Items[i];
                    AccountInfo account = (AccountInfo)listViewItem.Tag;
                    if (account.ActiveStatus == ActiveStatus.AlreadyActive || account.ActiveStatus == ActiveStatus.AppForbided)
                        accountInfos.Add(account);
                }
            }
            if (accountInfos.Count > 1)
            {
                if (MessageBox.Show(string.Format("确定删除选择帐号的好友？", accountInfos.Count.ToString()), "请确定", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    Thread t = new Thread(new ParameterizedThreadStart(DeleteFriend));
                    t.Start(accountInfos);
                    lstThread.Add(t);
                }
            }
            else
            {
                MessageBox.Show("选择账户数应多于一个并且选择账户应以验证激活状态！");
            }
        }

        void DeleteFriend(object obj)
        {
            this.Invoke(new DSetControlDisabled(SetControlDisabled));

            this.Invoke(new DAppendText(AppendText),string.Format("[{0}]：批量删除好友：\n",DateTime.Now.ToString("HH:mm:ss")));

            IList<AccountInfo> accountInfos = (List<AccountInfo>)obj;
            for (int i = 0; i < accountInfos.Count; i++)
            {
                AccountInfo accountInfo = accountInfos[i];
                User user = new User();
                this.Invoke(new DAppendText(AppendText),
                    string.Format("[{0}]：[{1}]开始登录系统……",
                        DateTime.Now.ToString("HH:mm:ss"),
                        string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name)));
                if (user.Login(accountInfo))
                {
                    accountInfo.FriendInfos = user.GetAllUserInfos();

                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：[{1}]成功登录系统，并获取好友列表！",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name)));

                    for (int j = 0; j < accountInfo.FriendInfos.Count; j++)
                    {
                        SimpleUserInfo userInfo = (SimpleUserInfo)accountInfo.FriendInfos[j];

                        user.DeleteFriend(userInfo);

                        this.Invoke(new DAppendText(AppendText), string.Format("[{0}]：[{1}]删除好友进度：({2})，{3} {4}(总)",
                                DateTime.Now.ToString("HH:mm:ss"),
                                string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name),
                                string.Format("{0},{1}", userInfo.uid, userInfo.real_name),
                                string.Format("{0}/{1}", (j + 1).ToString(), accountInfo.FriendInfos.Count.ToString()),
                                string.Format("{0}/{1}", (i + 1).ToString(), accountInfos.Count.ToString())));
                        if (j + 1 < accountInfo.FriendInfos.Count)
                            Thread.Sleep(delayConnect * 1000);
                    }

                    accountInfo.FriendInfos = new List<SimpleUserInfo>();

                    Account.StaticFriends(accountInfo);

                    user.Logout();

                    this.Invoke(new DAppendText(AppendText),
                        string.Format("\n[{0}]：[{1}]删除所有好友完成，退出系统！\n",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name)));
                }
            }
            this.Invoke(new DAppendText(AppendText), string.Format("[{0}]：完成帐号好友删除！", DateTime.Now.ToString("HH:mm:ss")));
            this.Invoke(new DSetControlDisabled(RestoreControlEnabled));
        }

        void UseMOTOVE66Card(object obj)
        {
            this.Invoke(new DSetControlDisabled(SetControlDisabled));

            this.Invoke(new DAppendText(AppendText),
               string.Format("[{0}]：使用MOTO VE66场景卡……\n",
                   DateTime.Now.ToString("HH:mm:ss")));

            IList<AccountInfo> accountInfos = (List<AccountInfo>)obj;
            for (int i = 0; i < accountInfos.Count; i++)
            {
                AccountInfo accountInfo = accountInfos[i];
                User user = new User();
                this.Invoke(new DAppendText(AppendText),
                    string.Format("[{0}]：[{1}]开始登录系统……",
                        DateTime.Now.ToString("HH:mm:ss"),
                        string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name)));
                if (user.Login(accountInfo))
                {
                    this.Invoke(new DAppendText(AppendText),
                        string.Format("[{0}]：[{1}]成功登录系统！",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name)));

                    int sceneMinute = user.GetSceneMinute();

                    this.Invoke(new DAppendText(AppendText),
                      string.Format("[{0}]：[{1}]获取当前停车收入：{2}元/分钟！",
                          DateTime.Now.ToString("HH:mm:ss"),
                          string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name),
                            string.Format("{0}", sceneMinute.ToString())));

                    if (sceneMinute >= 11)
                    {
                        this.Invoke(new DAppendText(AppendText),
                          string.Format("[{0}]：[{1}]不需要升级场景！\n",
                              DateTime.Now.ToString("HH:mm:ss"),
                              string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name)));
                    }
                    else
                    {
                        string verify = user.GetVerify();

                        this.Invoke(new DAppendText(AppendText),
                          string.Format("[{0}]：[{1}]获取VerifyCode：{2}\n",
                              DateTime.Now.ToString("HH:mm:ss"),
                              string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name),
                                string.Format("{0}", verify)));

                        this.Invoke(new DAppendText(AppendText),
                          string.Format("[{0}]：[{1}]使用MOTO VE66场景卡：",
                              DateTime.Now.ToString("HH:mm:ss"),
                              string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name)));

                        this.Invoke(new DAppendText(AppendText),
                          string.Format("[{0}]：[{1}]：{2} 进度 {3}",
                              DateTime.Now.ToString("HH:mm:ss"),
                              string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name),
                                Park.CardFreeScene(verify, "18"),
                                string.Format("{0}/{1}", (i + 1).ToString(), accountInfos.Count.ToString())));
                    }

                    user.Logout();

                    this.Invoke(new DAppendText(AppendText),
                        string.Format("\n[{0}]：[{1}]退出系统！\n",
                            DateTime.Now.ToString("HH:mm:ss"),
                            string.Format("{0},{1}", accountInfo.UserInfo.uid, accountInfo.UserInfo.real_name)));
                }
            }
            this.Invoke(new DAppendText(AppendText), string.Format("[{0}]：完成使用MOTO VE66场景卡！", DateTime.Now.ToString("HH:mm:ss")));
            this.Invoke(new DSetControlDisabled(RestoreControlEnabled));
        }

        private void button33_Click(object sender, EventArgs e)
        {
            IList<AccountInfo> accountInfos = new List<AccountInfo>();
            for (int i = 0; i < this.listView1.Items.Count; i++)
            {
                if (this.listView1.Items[i].Checked)
                {
                    ListViewItem listViewItem = this.listView1.Items[i];
                    AccountInfo account = (AccountInfo)listViewItem.Tag;
                    if (account.ActiveStatus == ActiveStatus.AlreadyActive)
                        accountInfos.Add(account);
                }
            }
            if (accountInfos.Count > 0)
            {
                this.SetControlDisabled();

                Thread t = new Thread(new ParameterizedThreadStart(UseMOTOVE66Card));
                t.Start(accountInfos);
                lstThread.Add(t);
            }
            else
            {
                MessageBox.Show("尚未选定帐号或者选定账户需要已验证激活状态！");
            }
        }

        private void button34_Click(object sender, EventArgs e)
        {
            IList<AccountInfo> accountInfos = new List<AccountInfo>();
            for (int i = 0; i < this.listView1.Items.Count; i++)
            {
                if (this.listView1.Items[i].Checked)
                {
                    ListViewItem listViewItem = this.listView1.Items[i];
                    AccountInfo account = (AccountInfo)listViewItem.Tag;
                    if (account.ActiveStatus == ActiveStatus.AlreadyActive)
                        accountInfos.Add(account);
                }
            }
            if (accountInfos.Count > 0)
            {
                this.SetControlDisabled();

                User user = new User();
                if (user.Login(accountInfos[0]))
                {
                    string verify = user.GetVerify();

                    for (int i = 0; i < 250; i++)
                    {
                        Console.WriteLine(Guess.DelGuess(205383, verify));
                        Thread.Sleep(2000);
                    }
                }


                //Thread t = new Thread(new ParameterizedThreadStart(UseMOTOVE66Card));
                //t.Start(accountInfos);
                //lstThread.Add(t);
            }
            else
            {
                MessageBox.Show("尚未选定帐号或者选定账户需要已验证激活状态！");
            }

        }

        private void button35_Click(object sender, EventArgs e)
        {

        }

    }
}
